File tree 3 files changed +52
-0
lines changed
solution/1900-1999/1996.The Number of Weak Characters in the Game
3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,25 @@ class Solution {
98
98
}
99
99
```
100
100
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
+
101
120
### ** C++**
102
121
103
122
``` cpp
Original file line number Diff line number Diff line change @@ -82,6 +82,25 @@ class Solution {
82
82
}
83
83
```
84
84
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
+
85
104
### ** C++**
86
105
87
106
``` cpp
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments