[
array
two pointers
sliding window
]
Leetcode 0674 Longest Continuous Increasing Subsequence
Problem statement
https://leetcode.com/problems/longest-continuous-increasing-subsequence/
Solution
Just do what is asked: use two pointers beg
and end
, increase end
if next number is greater than current; make both beg
and end
equal to end + 1
in opposite case.
Complexity
Time complexity is O(n)
, space complexity is O(1)
.
Code
class Solution:
def findLengthOfLCIS(self, nums):
beg, end, ans = 0, 0, int(len(nums) > 0)
while end < len(nums) - 1:
if nums[end] < nums[end+1]:
end += 1
else:
beg, end = end + 1, end + 1
ans = max(ans, end - beg + 1)
return ans