728x90
https://leetcode.com/problems/arithmetic-subarrays
class Solution:
def checkArithmeticSubarrays(self, nums: List[int], l: List[int], r: List[int]) -> List[bool]:
result = []
for i in range(0, len(l)):
subarray = nums[l[i]:r[i]+1]
subarray.sort()
if len(subarray) < 2:
result.append(False)
break
d = subarray[1] - subarray[0]
arithmetic = True
for j in range(1, len(subarray)):
if subarray[j] - subarray[j-1] != d:
arithmetic = False
break
result.append(arithmetic)
return result
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 2367. Number of Arithmetic Triplets (0) | 2024.02.22 |
---|---|
[Leetcode] 2325. Decode the Message (0) | 2024.02.21 |
[Leetcode] 1656. Design an Ordered Stream (0) | 2024.02.19 |
[Leetcode] 535. Encode and Decode TinyURL (0) | 2024.02.18 |
[Leetcode] 1365. How Many Numbers Are Smaller Than the Current Number (0) | 2024.02.09 |