Skip to content

Commit 5e5b453

Browse files
authored
Create HeightChecker.java
1 parent 08692af commit 5e5b453

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

easy/HeightChecker.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//1051. Height Checker
2+
class Solution {
3+
public int heightChecker(int[] heights) {
4+
int[] frequencies = new int[101];
5+
for (int height : heights) {
6+
frequencies[height]++;
7+
}
8+
int currHeight = 1;
9+
int mismatchCount = 0;
10+
for (int height : heights) {
11+
while (frequencies[currHeight] == 0) {
12+
currHeight++;
13+
}
14+
if (currHeight != height) {
15+
mismatchCount++;
16+
}
17+
frequencies[currHeight]--;
18+
}
19+
return mismatchCount;
20+
}
21+
}

0 commit comments

Comments
 (0)