978-Longest-Turbulent-Subarray
Sat 17 May 2025
https://leetcode.com/problems/longest-turbulent-subarray
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
def maxTurbulenceSize(self, A: List[int]) -> int:
ans = 1
increasing = 1
decreasing = 1
for i in range(1, len(A)):
if A[i] > A[i - 1]:
increasing = decreasing + 1
decreasing = 1
elif A[i] < A[i - 1]:
decreasing = increasing + 1
increasing = 1
else:
increasing = 1
decreasing = 1
ans = max(ans, max(increasing, decreasing))
return ans
new Solution().maxTurbulenceSize()
Score: 5
Category: leetcode