mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Merge branch 'youngyangyang04:master' into master
This commit is contained in:
@ -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:
|
||||
|
||||
> 动态规划:
|
||||
|
@ -119,7 +119,7 @@ C++代码如下:
|
||||
class Solution {
|
||||
public:
|
||||
vector<int> dailyTemperatures(vector<int>& T) {
|
||||
// 递减栈
|
||||
// 递增栈
|
||||
stack<int> st;
|
||||
vector<int> result(T.size(), 0);
|
||||
st.push(0);
|
||||
@ -150,7 +150,7 @@ public:
|
||||
class Solution {
|
||||
public:
|
||||
vector<int> dailyTemperatures(vector<int>& T) {
|
||||
stack<int> st; // 递减栈
|
||||
stack<int> st; // 递增栈
|
||||
vector<int> 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
|
||||
/**
|
||||
* 单调栈,栈内顺序要么从大到小 要么从小到大,本题从大到笑
|
||||
* 单调栈,栈内顺序要么从大到小 要么从小到大,本题从大到小
|
||||
* <p>
|
||||
* 入站元素要和当前栈内栈首元素进行比较
|
||||
* 若大于栈首则 则与元素下标做差
|
||||
|
Reference in New Issue
Block a user