본문 바로가기

IT/코딩테스트

[Leetcode] 1051. Height Checker

728x90

https://leetcode.com/problems/height-checker/

class Solution:
    def heightChecker(self, heights: List[int]) -> int:
        expected = heights.copy()
        expected.sort()

        count = 0
        for i in range(len(heights)):
            if heights[i] != expected[i]:
                count += 1

        return count

 

728x90

'IT > 코딩테스트' 카테고리의 다른 글

[Leetcode] 1075. Project Employees I  (0) 2023.09.04
[Leetcode] 2843. Count Symmetric Integers  (0) 2023.09.03
[Leetcode] 88. Merge Sorted Array  (1) 2023.09.02
[Leetcode] 1089. Duplicate Zeros  (0) 2023.09.02
[Leetcode] 577. Employee Bonus  (0) 2023.09.01