Longest Continuous Increasing Subsequence — LeetCode 674 Python Solution
EasyArray
- Problem
- #674
- Reading time
- 2 min
- Source
- leetcode.com
The problem
Given an unsorted array of integers nums, return the length of the longest continuous increasing subsequence (i.e. subarray).
Example
- Input
- nums = [1,3,5,4,7]
- Output
- 3
- Explanation
- The longest continuous increasing subsequence is [1,3,5] with length 3.
Python solution
Python
class Solution:
def findLengthOfLCIS(self, nums: List[int]) -> int:
ans = cnt = 1
for i, x in enumerate(nums[1:]):
if nums[i] < x:
cnt += 1
ans = max(ans, cnt)
else:
cnt = 1
return ansComplexity
| Measure | Complexity |
|---|---|
| Time | O(n), where n is the length of the array nums |
| Space | O(1) auxiliary |
Related problems
Frequently asked questions
- How hard is LeetCode 674. Longest Continuous Increasing Subsequence?
- LeetCode 674. Longest Continuous Increasing Subsequence is rated Easy on LeetCode.
- What is the time complexity of LeetCode 674. Longest Continuous Increasing Subsequence?
- The Python solution on this page runs in O(n), where n is the length of the array nums.
- What is the space complexity of LeetCode 674. Longest Continuous Increasing Subsequence?
- The Python solution on this page uses O(1) auxiliary space.
- What topics does LeetCode 674. Longest Continuous Increasing Subsequence cover?
- LeetCode 674. Longest Continuous Increasing Subsequence is tagged Array on LeetCode.