mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
26 lines
380 B
Go
26 lines
380 B
Go
|
package height_checker
|
||
|
|
||
|
func heightChecker(heights []int) int {
|
||
|
// count the heights
|
||
|
var counts [100]int
|
||
|
for _, h := range heights {
|
||
|
counts[h-1]++
|
||
|
}
|
||
|
|
||
|
incorrect := 0
|
||
|
|
||
|
expectedH := 1
|
||
|
for _, h := range heights {
|
||
|
for expectedH <= 100 && counts[expectedH-1] == 0 {
|
||
|
expectedH++
|
||
|
}
|
||
|
counts[expectedH-1]--
|
||
|
|
||
|
if expectedH != h {
|
||
|
incorrect++
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return incorrect
|
||
|
}
|