From 8399eed5204963a8968b7872cf4aa3c3ef486f8b Mon Sep 17 00:00:00 2001 From: Frogrey <35210929+Frogrey@users.noreply.github.com> Date: Mon, 3 Jan 2022 17:13:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20674.=20=E6=9C=80?= =?UTF-8?q?=E9=95=BF=E8=BF=9E=E7=BB=AD=E9=80=92=E5=A2=9E=E5=BA=8F=E5=88=97?= =?UTF-8?q?=20Java=20=E8=B4=AA=E5=BF=83=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0674.最长连续递增序列.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/problems/0674.最长连续递增序列.md b/problems/0674.最长连续递增序列.md index 98e09bf8..51d04e92 100644 --- a/problems/0674.最长连续递增序列.md +++ b/problems/0674.最长连续递增序列.md @@ -154,6 +154,8 @@ public: Java: + +> 动态规划: ```java /** * 1.dp[i] 代表当前下标最大连续值 @@ -180,6 +182,25 @@ Java: } ``` +> 贪心法: + +```Java +public static int findLengthOfLCIS(int[] nums) { + if (nums.length == 0) return 0; + int res = 1; // 连续子序列最少也是1 + int count = 1; + for (int i = 0; i < nums.length - 1; i++) { + if (nums[i + 1] > nums[i]) { // 连续记录 + count++; + } else { // 不连续,count从头开始 + count = 1; + } + if (count > res) res = count; + } + return res; +} +``` + Python: > 动态规划: From a828e5f247c8095171d60b74eefdbeb1a6b3a9a5 Mon Sep 17 00:00:00 2001 From: Martin Hsu <31008681+Martin-Hsu@users.noreply.github.com> Date: Tue, 4 Jan 2022 14:08:00 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Update=200739.=E6=AF=8F=E6=97=A5=E6=B8=A9?= =?UTF-8?q?=E5=BA=A6.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0739.每日温度.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/problems/0739.每日温度.md b/problems/0739.每日温度.md index d025e73c..d7489028 100644 --- a/problems/0739.每日温度.md +++ b/problems/0739.每日温度.md @@ -119,7 +119,7 @@ C++代码如下: class Solution { public: vector dailyTemperatures(vector& T) { - // 递减栈 + // 递增栈 stack st; vector result(T.size(), 0); st.push(0); @@ -150,7 +150,7 @@ public: class Solution { public: vector dailyTemperatures(vector& T) { - stack st; // 递减栈 + stack st; // 递增栈 vector result(T.size(), 0); for (int i = 0; i < T.size(); i++) { while (!st.empty() && T[i] > T[st.top()]) { // 注意栈不能为空 @@ -178,7 +178,7 @@ public: Java: ```java /** - * 单调栈,栈内顺序要么从大到小 要么从小到大,本题从大到笑 + * 单调栈,栈内顺序要么从大到小 要么从小到大,本题从大到小 *

* 入站元素要和当前栈内栈首元素进行比较 * 若大于栈首则 则与元素下标做差