코딩 공부/Leetcode

[Python] 1051. Height Checker

일하는 공학도 2025. 1. 31. 10:57
728x90

정렬한 리스트와 기존 리스트가 다른 숫자를 count하는 문제

 

class Solution:
    def heightChecker(self, heights: List[int]) -> int:
        heig = sorted(heights)
        a = 0
        for i in range(len(heig)):
            if heights[i] != heig[i]:
                a += 1
        return a

sorted한 리스트와 비교해서 a를 1씩 올려줌

 

Runtime : 0ms

Memory : 17.94MB (6.58%)

728x90