Skip to content

Commit c652187

Browse files
Update 0674.最长连续递增序列.md
1 parent a7d546c commit c652187

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

problems/0674.最长连续递增序列.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public static int findLengthOfLCIS(int[] nums) {
204204

205205
Python:
206206

207-
> 动态规划:
207+
DP
208208
```python
209209
class Solution:
210210
def findLengthOfLCIS(self, nums: List[int]) -> int:
@@ -219,8 +219,27 @@ class Solution:
219219
return result
220220
```
221221

222+
DP(优化版)
223+
```python
224+
class Solution:
225+
def findLengthOfLCIS(self, nums: List[int]) -> int:
226+
if not nums:
227+
return 0
228+
229+
max_length = 1
230+
current_length = 1
222231

223-
> 贪心法:
232+
for i in range(1, len(nums)):
233+
if nums[i] > nums[i - 1]:
234+
current_length += 1
235+
max_length = max(max_length, current_length)
236+
else:
237+
current_length = 1
238+
239+
return max_length
240+
241+
```
242+
贪心
224243
```python
225244
class Solution:
226245
def findLengthOfLCIS(self, nums: List[int]) -> int:

0 commit comments

Comments
 (0)