From 23e979a862a24327aa9ec45211c34492c613e762 Mon Sep 17 00:00:00 2001 From: lichuanming <1465802096@qq.com> Date: Mon, 7 Jun 2021 15:40:56 +0800 Subject: [PATCH] =?UTF-8?q?0674=20java=E8=A7=A3=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0674.最长连续递增序列.md | 26 ++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/problems/0674.最长连续递增序列.md b/problems/0674.最长连续递增序列.md index 46413d98..636ee0cc 100644 --- a/problems/0674.最长连续递增序列.md +++ b/problems/0674.最长连续递增序列.md @@ -156,7 +156,31 @@ public: Java: - +```java + /** + * 1.dp[i] 代表当前下表最大连续值 + * 2.递推公式 if(nums[i+1]>nums[i]) dp[i+1] = dp[i]+1 + * 3.初始化 都为1 + * 4.遍历方向,从其那往后 + * 5.结果推导 。。。。 + * @param nums + * @return + */ + public static int findLengthOfLCIS(int[] nums) { + int[] dp = new int[nums.length]; + for (int i = 0; i < dp.length; i++) { + dp[i] = 1; + } + int res = 1; + for (int i = 0; i < nums.length - 1; i++) { + if (nums[i + 1] > nums[i]) { + dp[i + 1] = dp[i] + 1; + } + res = res > dp[i + 1] ? res : dp[i + 1]; + } + return res; + } +``` Python: