Skip to content

Commit f20d7eb

Browse files
authored
Update README.md
1 parent 68e0771 commit f20d7eb

File tree

1 file changed

+1
-7
lines changed
  • solution/1000-1099/1051.Height Checker

1 file changed

+1
-7
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,7 @@ func heightChecker(heights []int) int {
147147
```ts
148148
function heightChecker(heights: number[]): number {
149149
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;
150+
return heights.reduce((acc, cur, i) => acc + (cur !== expected[i] ? 1 : 0), 0);
157151
}
158152
```
159153

0 commit comments

Comments
 (0)