2210. Count Hills and Valleys in an Array
Содержание
class Solution:
def countHillValley(self, nums: List[int]) -> int:
res = j = 0
for i in range(1, len(nums) - 1):
if nums[i] == nums[i + 1]:
continue
if nums[i] > nums[j] and nums[i] > nums[i + 1]:
res += 1
if nums[i] < nums[j] and nums[i] < nums[i + 1]:
res += 1
j = i
return res