Skip to content

Commit fabcfb1

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

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

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

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

145+
#### TypeScript
146+
147+
```ts
148+
function heightChecker(heights: number[]): number {
149+
const sorted = [...heights].sort((a, b) => a - b);
150+
let ans = 0;
151+
152+
for (let i = 0; i < heights.length; i++) {
153+
if (sorted[i] !== heights[i]) ans++;
154+
}
155+
156+
return ans;
157+
}
158+
```
159+
145160
<!-- tabs:end -->
146161

147162
<!-- solution:end -->

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

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

140+
#### TypeScript
141+
142+
```ts
143+
function heightChecker(heights: number[]): number {
144+
const sorted = [...heights].sort((a, b) => a - b);
145+
let ans = 0;
146+
147+
for (let i = 0; i < heights.length; i++) {
148+
if (sorted[i] !== heights[i]) ans++;
149+
}
150+
151+
return ans;
152+
}
153+
```
154+
140155
<!-- tabs:end -->
141156

142157
<!-- solution:end -->
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 sorted = [...heights].sort((a, b) => a - b);
3+
let ans = 0;
4+
5+
for (let i = 0; i < heights.length; i++) {
6+
if (sorted[i] !== heights[i]) ans++;
7+
}
8+
9+
return ans;
10+
}

0 commit comments

Comments
 (0)