728x90
난이도 : easy
리스트 nums 내의 인접한 요소가 번갈아서 홀 짝 or 짝 홀과 같은 형식으로 나타나는지 확인하는 문제
홀수와 짝수가 번갈아서 나와야 한다면, 두 요소를 더하면 무조건 홀수가 나와야 True가 된다.
class Solution:
def isArraySpecial(self, nums: List[int]) -> bool:
n = len(nums)
for i in range(1, n):
if (nums[i-1] + nums[i]) % 2 == 0:
return False
break
return True
인접한 두 요소를 더했을 때 짝수가 된다면, False를 return
모든 요소가 통과되면 True return
Runtime : 0ms
Memory : 17.80MB (48.73%)
728x90
'코딩 공부 > Leetcode' 카테고리의 다른 글
[Python] 977. Squares of a Sorted Array (0) | 2025.02.07 |
---|---|
[Python] 1726. Tuple with Same Product (0) | 2025.02.06 |
[Python] 141. Linked List Cycle (0) | 2025.02.05 |
[Python] 707. Design Linked List (0) | 2025.02.04 |
[Python] 1800. Maximum Ascending Subarray Sum (0) | 2025.02.04 |