1051. Height Checker

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1051

class Solution:
    def heightChecker(self, heights: List[int]) -> int:
        cnt = [0] * 101
        for h in heights:
            cnt[h] += 1
        res = i = 0
        for j in range(1, 101):
            while cnt[j]:
                cnt[j] -= 1
                if heights[i] != j:
                    res += 1
                i += 1
        return res