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; } };
原文地址:https://www.cnblogs.com/ymjyqsx/p/9567417.html
时间: 2024-10-08 05:00:30