自己写了个,res容器计算所有递增的数,找出最大的数列。有点繁琐。
[cpp] view plain copy
- class Solution {
- public:
- int findLengthOfLCIS(vector<int>& nums) {
- int a=nums.size();
- int cnt=1;
- vector<int> res;
- if (a==0) return 0;
- if (a==1) return 1;
- if (a>=2){
- for(int i=1;i<a;i++)
- {
- if( nums[i]<=nums[i-1])
- {
- res.push_back(cnt);
- cnt=1;
- }
- else if(i==a-1&&nums[i]>nums[i-1])
- {
- cnt=cnt+1;
- res.push_back(cnt);
- }
- else
- cnt=cnt+1;
- }
- }
- int max=res[0];
- for(int j=0;j<res.size();j++)
- if (res[j]>max) max=res[j];
- return max;
- }
- };
674. Longest Continuous Increasing Subsequence
最新推荐文章于 2024-09-28 18:22:46 发布
自己写了个,res容器计算所有递增的数,找出最大的数列。有点繁琐。