본문 바로가기
python-algorithm

leetcode 2784. Check if Array is Good

by 무적김두칠 2024. 2. 14.

https://leetcode.com/problems/check-if-array-is-good/description/

 

LeetCode - The World's Leading Online Programming Learning Platform

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

1
2
3
4
5
6
7
8
9
10
11
class Solution:
    def isGood(self, nums: List[int]) -> bool:
        n = max(nums)
        base = [i for i in range(1, n + 1)]
        base.append(n)
        nums.sort()
        if nums == base:
            return True
        else:
            return False
        
cs

base 리스트를 만들어 비교해주면됩니다.

반응형

댓글