C++ O(n*n) dp solution.


  • 0
    C
    int lengthOfLIS(vector<int>& nums) {
        if (nums.size() == 0)
            return 0;
        vector<int> dp(nums.size(), 1);
        for (unsigned int i=0; i<nums.size(); i++) 
            for (unsigned int j=0; j<i; j++)
                if (nums[i]>nums[j]) 
                    dp[i] = max(dp[i], dp[j]+1);
        return *max_element(dp.begin(), dp.end());
    }

Log in to reply
 

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