乐趣区

leetcode-674

public int findLengthOfLCIS(int[] nums) {if(nums == null || nums.length == 0)
            return 0;
            
        int sum = 1;
        int p = 0;
        int[] count = new int[nums.length];
        
        for(int i = 1; i < nums.length; i++){if(nums[i-1] < nums[i]){sum++;}else{count[p] = sum;
                sum = 1;
                p = i;
            }

        }
        
        count[p] = sum;
        int max = 0;
        for(int i = 0; i < count.length; i++){if(count[i] > max)
                max = count[i];
        }
        return max;
}

法二,用临时变量,减少了空间

public static int findLengthOfLCIS(int[] nums) {if(nums.length == 0 || nums == null)
            return 0;
        int sum = 1;
        int max = 0;

        for(int i = 1; i < nums.length; i++){if(nums[i-1] < nums[i]){sum++;}else{max = Math.max(max, sum);
                sum = 1;
            }

        }
        max = Math.max(max, sum);

        return max;
}
退出移动版