shortest java code time: O(n), space: O(1)


  • 0
    class Solution {
        public int findLengthOfLCIS(int[] nums) {
            if (nums == null || nums.length == 0) return 0;
            int result = 1, temp = 1;
            for (int i = 0; i < nums.length - 1; i++) {
                temp = nums[i+1] > nums[i] ? temp + 1 : 1;
                result = Math.max(result, temp);
            }
            return result;
        }
    }
    

Log in to reply
 

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