Обновлено: 2024-03-12
1 мин
Содержание
class Solution:
def countMatchingSubarrays(self, nums: List[int], pattern: List[int]) -> int:
def f(a: int, b: int) -> int:
return 0 if a == b else (1 if a < b else -1)
res = 0
for i in range(len(nums) - len(pattern)):
res += all(
f(nums[i + k], nums[i + k + 1]) == p for k, p in enumerate(pattern)
)
return res