Skip to content

Commit 1a074ae

Browse files
committed
feat: add typescript solution to lc problem: No.1996
No.1996.The Number of Weak Characters in the Game
1 parent 05f229e commit 1a074ae

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

solution/1900-1999/1996.The Number of Weak Characters in the Game/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,25 @@ class Solution {
9898
}
9999
```
100100

101+
### **TypeScript**
102+
103+
```ts
104+
function numberOfWeakCharacters(properties: number[][]): number {
105+
properties.sort((a, b) => (a[0] != b[0]) ? (b[0] - a[0]) : (a[1] - b[1]));
106+
107+
let ans = 0;
108+
let max = 0;
109+
for (let [ , b] of properties) {
110+
if (b < max) {
111+
ans++;
112+
} else {
113+
max = b;
114+
}
115+
}
116+
return ans;
117+
};
118+
```
119+
101120
### **C++**
102121

103122
```cpp

solution/1900-1999/1996.The Number of Weak Characters in the Game/README_EN.md

+19
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,25 @@ class Solution {
8282
}
8383
```
8484

85+
### **TypeScript**
86+
87+
```ts
88+
function numberOfWeakCharacters(properties: number[][]): number {
89+
properties.sort((a, b) => (a[0] != b[0]) ? (b[0] - a[0]) : (a[1] - b[1]));
90+
91+
let ans = 0;
92+
let max = 0;
93+
for (let [ , b] of properties) {
94+
if (b < max) {
95+
ans++;
96+
} else {
97+
max = b;
98+
}
99+
}
100+
return ans;
101+
};
102+
```
103+
85104
### **C++**
86105

87106
```cpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function numberOfWeakCharacters(properties: number[][]): number {
2+
properties.sort((a, b) => (a[0] != b[0]) ? (b[0] - a[0]) : (a[1] - b[1]));
3+
4+
let ans = 0;
5+
let max = 0;
6+
for (let [ , b] of properties) {
7+
if (b < max) {
8+
ans++;
9+
} else {
10+
max = b;
11+
}
12+
}
13+
return ans;
14+
};

0 commit comments

Comments
 (0)