674. Longest Continuous Increasing Subsequence 发表于 2022-01-28 DP1234567891011121314151617class Solution { public int findLengthOfLCIS(int[] nums) { // 定义 dp[i] 为以 nums[i] 结尾的最长连续递增子序列的长度 int[] dp = new int[nums.length]; Arrays.fill(dp, 1); int maxLength = 1; for (int i = 1; i < nums.length; i++) { if (nums[i] > nums[i - 1]) { dp[i] = dp[i - 1] + 1; } maxLength = Math.max(maxLength, dp[i]); } return maxLength; }} Greedy1234567891011121314151617class Solution { public int findLengthOfLCIS(int[] nums) { int maxLength = 1; int i = 0; for (int j = 1; j < nums.length; j++) { // LCIS: [i, j] if (nums[j] > nums[j - 1]) { maxLength = Math.max(maxLength, j - i + 1); } else { i = j; } } return maxLength; }} Reference674. Longest Continuous Increasing Subsequence