mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Update 0674.最长连续递增序列.md
This commit is contained in:
@ -204,7 +204,7 @@ public static int findLengthOfLCIS(int[] nums) {
|
|||||||
|
|
||||||
Python:
|
Python:
|
||||||
|
|
||||||
> 动态规划:
|
DP
|
||||||
```python
|
```python
|
||||||
class Solution:
|
class Solution:
|
||||||
def findLengthOfLCIS(self, nums: List[int]) -> int:
|
def findLengthOfLCIS(self, nums: List[int]) -> int:
|
||||||
@ -219,8 +219,27 @@ class Solution:
|
|||||||
return result
|
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
|
```python
|
||||||
class Solution:
|
class Solution:
|
||||||
def findLengthOfLCIS(self, nums: List[int]) -> int:
|
def findLengthOfLCIS(self, nums: List[int]) -> int:
|
||||||
|
Reference in New Issue
Block a user