mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
动态规划 最长连续递增序列 java 动态规划状态压缩优化
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user