Why is it accepted?


  • -1
    X
    public class Solution {
        public int lengthOfLIS(int[] nums) {
            if (null == nums || nums.length == 0) {
    			return 0;
    		}
    		int max = 1;
    		for (int i = 0; i < nums.length; i++) {
    			int count = 1;
    			int prev = nums[i];
    			for (int j = i + 1; j < nums.length; j++) {
    				if (nums[j] > prev) {
    					count++;
    					prev = nums[j];
    				}
    			}
    			max = Math.max(max, count);
    		}
    		return max;
        }
    }
    

    i think it is overtime.


  • 0
    D

    The time complexity of your algorithm is O(n^2).
    However, your code will return 4 when the input is [3,5,6,2,5,4,19,5,6,7,12].
    Actually it should return 6.


  • 0

    Thanks, this test case had been added.


Log in to reply
 

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