728x90
난이도 : easy
리스트 nums가 sorted array인지 확인하는 문제.
class Solution:
def check(self, nums: List[int]) -> bool:
n = len(nums)
while n > 0:
if nums == sorted(nums):
return True
else:
a = nums.pop(0)
nums.append(a)
n -= 1
return False
while 문을 만들어서, 정렬한 리스트와 동일하면 true를 return.
nums의 길이인 n만큼 돌리는 동안 정렬한 리스트와 동일한 게 안 나오면 False.
Runtime : 3ms (9.91%)
Memory : 17.82MB (30.10%)
728x90
'코딩 공부 > Leetcode' 카테고리의 다른 글
[Python] 1800. Maximum Ascending Subarray Sum (0) | 2025.02.04 |
---|---|
[Python] 3105. Longest Strictly Increasing or Strictly Decreasing Subarray (0) | 2025.02.03 |
[Python] 448. Find All Numbers Disappeared in an Array (0) | 2025.02.02 |
[Python] 414. Third Maximum Number (0) | 2025.02.01 |
[Python] 1051. Height Checker (0) | 2025.01.31 |