diff --git a/problems/0674.最长连续递增序列.md b/problems/0674.最长连续递增序列.md index 79a8311d..0d9866a0 100644 --- a/problems/0674.最长连续递增序列.md +++ b/problems/0674.最长连续递增序列.md @@ -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: