Java O(N) solution


  • 0
    C
    public int findLengthOfLCIS(int[] nums) {
        if(nums.length <= 1) return nums.length;
        
        int j = 0, maxlen = 0, len = 1;
        while(j < nums.length) {
            if(j>0 && nums[j] > nums[j-1])
                len++;
            else
                len = 1;
            maxlen = Math.max(maxlen, len);
            j++;
        }
        return maxlen;
    }

Log in to reply
 

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