mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
16 lines
268 B
Go
16 lines
268 B
Go
package leetcode
|
|
|
|
import "sort"
|
|
|
|
func heightChecker(heights []int) int {
|
|
result, checker := 0, []int{}
|
|
checker = append(checker, heights...)
|
|
sort.Ints(checker)
|
|
for i := 0; i < len(heights); i++ {
|
|
if heights[i] != checker[i] {
|
|
result++
|
|
}
|
|
}
|
|
return result
|
|
}
|