The longest continuous increasing sequence java

Given an unsorted integer array, find the longest continuously increasing subsequence, and return the length of the sequence.

The continuously increasing subsequence can be determined by two subscripts l and r (l <r). If for each l <= i <r, there is nums[i] <nums[i + 1], then the subsequence [ nums[l], nums[l + 1], …, nums[r-1], nums[r]] are successively increasing subsequences.

Example 1:

Input: nums = [1,3,5,4,7]
Output: 3
Explanation: The longest continuous increasing sequence is [1,3,5], and the length is 3.
Although [1,3,5,7] is also an ascending subsequence, it is not continuous, because 5 and 7 are separated by 4 in the original array.
Example 2:

Input: nums = [2,2,2,2,2]
Output: 1
Explanation: The longest continuous increasing sequence is [2], and the length is 1.

prompt:

0 <= nums.length <= 104
-109 <= nums[i] <= 109

Source: LeetCode (LeetCode)
Link: https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence
Copyright is owned by LeetCode . For commercial reprints, please contact the official authorization. For non-commercial reprints, please indicate the source.

Idea: A simple dp question is to pit len==0

class Solution {
    
    
    public int findLengthOfLCIS(int[] nums) {
    
    
        int len = nums.length;
        if(len==1)
            return 1;
        if(len==0)
            return 0;
        int[] mark = new int[len];
        for(int i=0;i<len;i++){
    
    
            mark[i] = 1;
        }
        int[] dp = new int[len];
        for(int i=1;i<len;i++)
            for(int j=0;j<i;j++)
            {
    
    
                if(j==i-1){
    
    
                    if(nums[i]>nums[j])
                        mark[i] = Math.max(mark[i],mark[j]+1);
                }
            }
        Arrays.sort(mark);
        return mark[len-1];
    }
}

Guess you like

Origin blog.csdn.net/weixin_43824233/article/details/113093770