File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -204,7 +204,7 @@ public static int findLengthOfLCIS(int[] nums) {
204
204
205
205
Python:
206
206
207
- > 动态规划:
207
+ DP
208
208
``` python
209
209
class Solution :
210
210
def findLengthOfLCIS (self , nums : List[int ]) -> int :
@@ -219,8 +219,27 @@ class Solution:
219
219
return result
220
220
```
221
221
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
222
231
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
+ 贪心
224
243
``` python
225
244
class Solution :
226
245
def findLengthOfLCIS (self , nums : List[int ]) -> int :
You can’t perform that action at this time.
0 commit comments