Only 9 lines c++ o(nlogn) solution


  • 2
    T
    class Solution {
    public:
        int lengthOfLIS(vector<int>& nums) {
            	vector<int> min;
    	for(int num : nums){
    		auto it = lower_bound(min.begin(), min.end(), num);
    		if(it!=min.end())
    			*it=num;
    		else
    			min.push_back(num);
    	    }
    	return min.size();
        }
    };

  • 0
    J

    as i was not that sure lower_bound would implement the binary search for the sorted array;


Log in to reply
 

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