File tree Expand file tree Collapse file tree 3 files changed +40
-2
lines changed
solution/1000-1099/1051.Height Checker Expand file tree Collapse file tree 3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -142,6 +142,20 @@ func heightChecker(heights []int) int {
142
142
}
143
143
```
144
144
145
+ #### TypeScript
146
+
147
+ ```` ts
148
+ function heightChecker(heights : number []): number {
149
+ const expected = [... heights ].sort ((a , b ) => a - b );
150
+ let ans = 0 ;
151
+
152
+ for (let i = 0 ; i < heights .length ; i ++ ) {
153
+ if (expected [i ] !== heights [i ]) ans ++ ;
154
+ }
155
+
156
+ return ans ;
157
+ }` ` `
158
+
145
159
<!-- tabs:end -->
146
160
147
161
<!-- solution:end -->
@@ -172,7 +186,7 @@ class Solution:
172
186
ans += 1
173
187
i += 1
174
188
return ans
175
- ```
189
+ ````
176
190
177
191
#### Java
178
192
Original file line number Diff line number Diff line change @@ -137,6 +137,20 @@ func heightChecker(heights []int) int {
137
137
}
138
138
```
139
139
140
+ #### TypeScript
141
+
142
+ ```` ts
143
+ function heightChecker(heights : number []): number {
144
+ const expected = [... heights ].sort ((a , b ) => a - b );
145
+ let ans = 0 ;
146
+
147
+ for (let i = 0 ; i < heights .length ; i ++ ) {
148
+ if (expected [i ] !== heights [i ]) ans ++ ;
149
+ }
150
+
151
+ return ans ;
152
+ }` ` `
153
+
140
154
<!-- tabs:end -->
141
155
142
156
<!-- solution:end -->
@@ -163,7 +177,7 @@ class Solution:
163
177
ans += 1
164
178
i += 1
165
179
return ans
166
- ```
180
+ ````
167
181
168
182
#### Java
169
183
Original file line number Diff line number Diff line change
1
+ function heightChecker ( heights : number [ ] ) : number {
2
+ const expected = [ ...heights ] . sort ( ( a , b ) => a - b ) ;
3
+ let ans = 0 ;
4
+
5
+ for ( let i = 0 ; i < heights . length ; i ++ ) {
6
+ if ( expected [ i ] !== heights [ i ] ) ans ++ ;
7
+ }
8
+
9
+ return ans ;
10
+ }
You can’t perform that action at this time.
0 commit comments