动态规划 最长连续递增序列 java 动态规划状态压缩优化

This commit is contained in:
yangzhaoMP
2024-03-06 14:59:28 +08:00
parent 9932bebde8
commit 1474a28a53

View File

@ -186,7 +186,23 @@ public:
return res;
}
```
> 动态规划状态压缩
```java
class Solution {
public int findLengthOfLCIS(int[] nums) {
// 记录以 前一个元素结尾的最长连续递增序列的长度 和 以当前 结尾的......
int beforeOneMaxLen = 1, currentMaxLen = 0;
// res 赋最小值返回的最小值1
int res = 1;
for (int i = 1; i < nums.length; i ++) {
currentMaxLen = nums[i] > nums[i - 1] ? beforeOneMaxLen + 1 : 1;
beforeOneMaxLen = currentMaxLen;
res = Math.max(res, currentMaxLen);
}
return res;
}
}
```
> 贪心法:
```Java