mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Update 0674.最长连续递增序列.md
This commit is contained in:
@ -204,7 +204,7 @@ public static int findLengthOfLCIS(int[] nums) {
|
||||
|
||||
Python:
|
||||
|
||||
> 动态规划:
|
||||
DP
|
||||
```python
|
||||
class Solution:
|
||||
def findLengthOfLCIS(self, nums: List[int]) -> int:
|
||||
@ -219,8 +219,27 @@ class Solution:
|
||||
return result
|
||||
```
|
||||
|
||||
DP(优化版)
|
||||
```python
|
||||
class Solution:
|
||||
def findLengthOfLCIS(self, nums: List[int]) -> int:
|
||||
if not nums:
|
||||
return 0
|
||||
|
||||
> 贪心法:
|
||||
max_length = 1
|
||||
current_length = 1
|
||||
|
||||
for i in range(1, len(nums)):
|
||||
if nums[i] > nums[i - 1]:
|
||||
current_length += 1
|
||||
max_length = max(max_length, current_length)
|
||||
else:
|
||||
current_length = 1
|
||||
|
||||
return max_length
|
||||
|
||||
```
|
||||
贪心
|
||||
```python
|
||||
class Solution:
|
||||
def findLengthOfLCIS(self, nums: List[int]) -> int:
|
||||
|
Reference in New Issue
Block a user