From c652187f747a2b7546f45e0f29cc985b929a8454 Mon Sep 17 00:00:00 2001 From: jianghongcheng <35664721+jianghongcheng@users.noreply.github.com> Date: Wed, 7 Jun 2023 03:59:52 -0500 Subject: [PATCH] =?UTF-8?q?Update=200674.=E6=9C=80=E9=95=BF=E8=BF=9E?= =?UTF-8?q?=E7=BB=AD=E9=80=92=E5=A2=9E=E5=BA=8F=E5=88=97.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0674.最长连续递增序列.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) 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: