Skip to content

Commit 324c6f4

Browse files
authored
Update Solution.ts
1 parent f20d7eb commit 324c6f4

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
function heightChecker(heights: number[]): number {
22
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;
3+
return heights.reduce((acc, cur, i) => acc + (cur !== expected[i] ? 1 : 0), 0);
104
}

0 commit comments

Comments
 (0)