Leetcode 1752 Solution
This article provides solution to leetcode question 1752 (arithmetic-subarrays)
Access this page by simply typing in "lcs 1752" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/arithmetic-subarrays
Solution
class Solution:
def checkArithmeticSubarrays(self, nums: List[int], l: List[int], r: List[int]) -> List[bool]:
ans = []
for i, j in zip(l, r):
subnums = nums[i:j + 1]
subnums.sort()
for k in range(2, len(subnums)):
if subnums[k] - subnums[k - 1] != subnums[k - 1] - subnums[k - 2]:
ans.append(False)
break
else:
ans.append(True)
return ans