Skip to content

Commit 0683588

Browse files
committed
feat: add ts solution to lc problem: No.1051
1 parent fbd3df3 commit 0683588

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

solution/1000-1099/1051.Height Checker/README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,20 @@ func heightChecker(heights []int) int {
142142
}
143143
```
144144

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+
145159
<!-- tabs:end -->
146160
147161
<!-- solution:end -->
@@ -172,7 +186,7 @@ class Solution:
172186
ans += 1
173187
i += 1
174188
return ans
175-
```
189+
````
176190

177191
#### Java
178192

solution/1000-1099/1051.Height Checker/README_EN.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,20 @@ func heightChecker(heights []int) int {
137137
}
138138
```
139139

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+
140154
<!-- tabs:end -->
141155
142156
<!-- solution:end -->
@@ -163,7 +177,7 @@ class Solution:
163177
ans += 1
164178
i += 1
165179
return ans
166-
```
180+
````
167181

168182
#### Java
169183

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}

0 commit comments

Comments
 (0)