1051. Height Checker

🟩 Easy

Solution

My Solution

func heightChecker(heights []int) int {
    nums := make([]int, len(heights))
    copy(nums, heights)
    
    sort.Ints(nums)
    count := 0

    for i, num := range nums {
        if num != heights[i] {
            count++
        }
    }


    return count
}
result

Leetcode: link

Last updated

Was this helpful?