EasyNo. 0674
Longest Continuous Increasing Subsequence — LeetCode 674 Python Solution
- Topics
- Array
- 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
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
- Time
- O(n)where n is the length of the array nums
- Space · auxiliary
- O(1)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0665 | Non-decreasing Array | Medium |
| 0057 | Insert Interval | Medium |
| 0228 | Summary Ranges | Easy |
| 0485 | Max Consecutive Ones | Easy |
| 0699 | Falling Squares | Hard |
| 0717 | 1-bit and 2-bit Characters | Easy |
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.