Skip to content

Commit 86510e6

Browse files
committed
added Longest Continuous Increasing Subsequence (easy)
1 parent 0a3f34e commit 86510e6

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
# Longest Continuous Increasing Subsequence
3+
[Leetcode Link](https://leetcode.com/problems/longest-continuous-increasing-subsequence/)
4+
5+
## Problem:
6+
7+
Given an unsorted array of integers, find the length of longest `continuous` increasing subsequence (subarray).
8+
9+
## Example:
10+
11+
```
12+
Input: [1,3,5,4,7]
13+
Output: 3
14+
Explanation: The longest continuous increasing subsequence is [1,3,5], its length is 3.
15+
Even though [1,3,5,7] is also an increasing subsequence, it's not a continuous one where 5 and 7 are separated by 4.
16+
```
17+
```
18+
Input: [2,2,2,2,2]
19+
Output: 1
20+
Explanation: The longest continuous increasing subsequence is [2], its length is 1.
21+
```
22+
23+
## Note:
24+
25+
Length of the array will not exceed 10,000.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from typing import List
2+
3+
class Solution:
4+
def findLengthOfLCIS(self, nums: List[int]) -> int:
5+
if len(nums) <= 1:
6+
return len(nums)
7+
curLength = 1
8+
maxLength = 1
9+
for i in range(1, len(nums)):
10+
if nums[i-1] < nums[i]:
11+
# print(nums[i], "is greater than", nums[i-1])
12+
curLength += 1
13+
# print("curLength:", curLength)
14+
else:
15+
curLength = 1
16+
maxLength = max(curLength, maxLength)
17+
# print("maxLength:", maxLength)
18+
return maxLength
19+
20+
21+
# test driver
22+
sol = Solution()
23+
arr = [1,3,5,4,7]
24+
print("Input:", arr)
25+
print("Output:", sol.findLengthOfLCIS(arr))

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Languages used: Java and Python
3838
- [Sqrt(x)](Easy/SqrtX)
3939
- [Shuffle the Array](Easy/ShuffleArray)
4040
- [Remove Duplicates from Sorted List](Easy/RemoveDuplicatesFromSortedList)
41+
- [Longest Continuous Increasing Subsequence](Easy/LongestIncreasingSubsequence)
4142
- Medium
4243
- [Minimum Add to Make Parentheses Valid](Medium/MinimumAddtoMakeParenthesesValid)
4344
- [Distribute Coins in Binary Tree](Medium/DistributionCoinsInBinaryTree)

0 commit comments

Comments
 (0)