Test case incomplete


  • 0
    Y
    public class Solution {
        public int lengthOfLIS(int[] nums) {
            if(nums == null || nums.length == 0) return 0; 
            int[] dp = new int[nums.length];
            dp[0] = nums[0];
            int end = 1;
            for(int i=1;i<nums.length;i++) {
                if(nums[i] > dp[end-1]) {
                    dp[end++] = nums[i];
                }else {
                    replace(dp,0,end-1,nums[i]);
                }
            }
            return end;
        }
        public void replace(int[] array, int left, int right, int target) {
            while(left < right-1){
                int mid = left + (right-left)/2;
                if(array[mid] == target) return;
                else if(array[mid] < target) left = mid;
                else right = mid;
            }
            //if(array[left] == target || array[right] == target) return;
            if(array[left] > target) array[left] = target;
            else array[right] = target;
        }
    }
    

    [4,10,4,3,8,9]
    should return 3, My code returns 4 but got accepted


  • 0

    @yzmys000 Thanks, I have added your test case.


Log in to reply
 

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