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 리스트를 만들어 비교해주면됩니다.
반응형
'python-algorithm' 카테고리의 다른 글
백준 10798 세로읽기 (1) | 2024.02.15 |
---|---|
leetcode 1732. Find the Highest Altitude (1) | 2024.02.15 |
leetcode 3024. Type of Triangle (0) | 2024.02.13 |
leetcode 3033. Modify the Matrix (1) | 2024.02.13 |
leetcode 2357. Make Array Zero by Subtracting Equal Amounts (1) | 2024.02.09 |
댓글