java dp solution


  • 0
    Y

    dp[i] is the longest subsequence ends in nums[i].

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

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.