Please add a case


  • 0
    F
    var lengthOfLIS = function(nums) {
        var len=nums.length;
            if(len===1)
                return 1;
        var temp,max=0,count;
        for(var i=0;i<len-1;i++){
            temp=nums[i];
            count=1;
            for(var k=i+1;k<len;k++){
                if(temp<nums[k]){
                    count++;
                    temp=nums[k];
                }
            }
            if(count>max){
                max=count;
            }
        }
        return max;
    };
    

    I got my code passed. But it actually wrong when use the below test case:
    [10,9,2,5,3,7,200,18,101,102,103]
    it should be 7 but instead it returns 4
    So please add this test case

    below is the code runs correctly:

    var re =function(res,nums,start,ans){
        if(start<0){
            return;
        }
        var len=nums.length;
        var temp,max=0;
            temp=nums[start];
            for(var k=start+1;k<len;k++){
                if(temp<nums[k]){
                    if(res[k]>max){
                        max=res[k];
                    }
                }
            }
        res[start]=max+1;
        if(max+1>ans[0]){
            ans[0]=max+1;
        }
        re(res,nums,start-1,ans);
    }
    var lengthOfLIS = function(nums) {
        var res=new Array(nums.length);
        var ans=[0];
        re(res,nums,nums.length-1,ans);
        return ans[0];
    };

  • 0

    Done. 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.