Search

Height Checker

문제 설명 : 제공된 키 목록 중 오름차순으로 정렬되지 않은 요소가 몇개인지 반환
풀이 방법
오름차순으로 정렬한 요소와 비교하여 갯수 반환
시간복잡도 : O(NlogN)O(NlogN)
성공 코드
class Solution: def heightChecker(self, heights: List[int]) -> int: sorted_heights = sorted(heights) result = 0 for item1, item2 in zip(heights, sorted_heights): if item1 != item2: result += 1 return result
Python
복사