leetcode300. Longest Increasing Subsequence 最长递增子序列
Posted 去做点事情
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode300. Longest Increasing Subsequence 最长递增子序列相关的知识,希望对你有一定的参考价值。
class Solution { public: int lengthOfLIS(vector<int>& nums) { int length = nums.size(); if(length <= 0) return 0; vector<int> result(length); for(int i = 0;i < length;i++) result[i] = 1; for(int i = 1;i < length;i++){ int max_sum = 1; for(int j = i-1;j >= 0;j--){ if(nums[i] > nums[j]){ int num = result[j] + 1; if(num > max_sum) max_sum = num; } } result[i] = max_sum; } int max = 1; for(int i = 0;i < length;i++){ if(result[i] > max) max = result[i]; } return max; } };
以上是关于leetcode300. Longest Increasing Subsequence 最长递增子序列的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode 300. Longest Increasing Subsequence
LeetCode 300. Longest Increasing Subsequence
LeetCode 300. Longest Increasing Subsequence
leetcode300.Longest Increasing Subsequence