mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Merge pull request #360 from z80160280/z80160280-patch-9
Update 0674.最长连续递增序列.md
This commit is contained in:
@ -184,6 +184,37 @@ Java:
|
||||
|
||||
Python:
|
||||
|
||||
> 动态规划:
|
||||
```python
|
||||
class Solution:
|
||||
def findLengthOfLCIS(self, nums: List[int]) -> int:
|
||||
if len(nums) == 0:
|
||||
return 0
|
||||
result = 1
|
||||
dp = [1] * len(nums)
|
||||
for i in range(len(nums)-1):
|
||||
if nums[i+1] > nums[i]: #连续记录
|
||||
dp[i+1] = dp[i] + 1
|
||||
result = max(result, dp[i+1])
|
||||
return result
|
||||
```
|
||||
|
||||
> 贪心法:
|
||||
```python
|
||||
class Solution:
|
||||
def findLengthOfLCIS(self, nums: List[int]) -> int:
|
||||
if len(nums) == 0:
|
||||
return 0
|
||||
result = 1 #连续子序列最少也是1
|
||||
count = 1
|
||||
for i in range(len(nums)-1):
|
||||
if nums[i+1] > nums[i]: #连续记录
|
||||
count += 1
|
||||
else: #不连续,count从头开始
|
||||
count = 1
|
||||
result = max(result, count)
|
||||
return result
|
||||
```
|
||||
|
||||
Go:
|
||||
|
||||
|
Reference in New Issue
Block a user