美文网首页
300. Longest Increasing Subseque

300. Longest Increasing Subseque

作者: 刘小小gogo | 来源:发表于2018-09-05 23:18 被阅读0次
image.png
参考:https://algorithm.yuanbin.me/zh-hans/dynamic_programming/longest_increasing_subsequence.html
image.png
class Solution {
public:
    int lengthOfLIS(vector<int>& nums) {
        vector<int> dp(nums.size(), 1);
        int n = nums.size();
        int max = 0;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < i; j++){
                if(nums[j] < nums[i] && dp[j] >= dp[i]){
                    dp[i] = dp[j] + 1;
                }
            }
            if(dp[i] >max) max = dp[i];
        }
        return max;
    }
};

相关文章

网友评论

      本文标题:300. Longest Increasing Subseque

      本文链接:https://www.haomeiwen.com/subject/ofttgftx.html