JavaScript solution (O^2)


  • 0
    L
    function lengthOfLIS(nums) {
    	var lis = [];
    	for (var i = 0; i < nums.length; i++) {
    		lis.push(1);
    		for (var j = 0; j < i; j++) {
    			if (nums[j] < nums[i]) lis[i] = Math.max(lis[i], lis[j] + 1);
    		}
    	}
    	return nums.length ? Math.max.apply(null, lis) : 0;
    }

Log in to reply
 

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