Longest Continuous Increasing Subsequence, LCIS
December 3, 2024Less than 1 minute
Longest Continuous Increasing Subsequence, LCIS
public int findLengthOfLCIS(int[] nums) {
if (nums == null || nums.length == 0) {
return 0;
}
int maxLength = 1; // 最长连续递增子序列的长度至少为1
int currentLength = 1; // 当前连续递增子序列的长度
for (int i = 1; i < nums.length; i++) {
if (nums[i] > nums[i - 1]) { // 如果当前元素大于前一个元素
currentLength++; // 增加当前连续递增子序列的长度
maxLength = Math.max(maxLength, currentLength); // 更新最大长度
} else {
currentLength = 1; // 重置当前连续递增子序列的长度
}
}
return maxLength; // 返回最长连续递增子序列的长度
}