mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
添加 674. 最长连续递增序列 Java 贪心法
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:
|
||||
|
||||
> 动态规划:
|
||||
|
Reference in New Issue
Block a user