4ms simple c++ solution


  • 0
    Y

    int Solution::lengthOfLIS(vector<int> &nums){
    if (nums.empty()) return 0;

    int LIS_ind = 1;
    
    for (int i = 1; i != nums.size(); ++i){
    	if (nums[i] > nums[LIS_ind-1]) {
    		nums[LIS_ind++] = nums[i];
    	}
    	else{
    		auto iter = lower_bound(nums.begin(), nums.begin()+LIS_ind, nums[i]);
    		*iter = nums[i];
    	}
    }
    
    return LIS_ind;
    

    }


  • 0
    S

    This is difficult to understand


Log in to reply
 

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