力扣-剑指Offer-57 和为s的连续正数序列
作者:互联网
Idea
枚举:
从每个数组的起点开始枚举
AC Code
class Solution {
public:
vector<vector<int>> findContinuousSequence(int target) {
vector<vector<int>> ans;
for(int i = 1;i<target;i++){
vector<int> cur;
cur.emplace_back(i);
int sum = i;
for(int j=i+1;j<target;j++){
sum+=j;
cur.emplace_back(j);
if(sum == target){
ans.emplace_back(cur);
break;
}
else if(sum>target) break;
}
}
return ans;
}
};
标签:emplace,cur,Offer,int,57,back,力扣,ans,sum 来源: https://blog.csdn.net/weixin_45774972/article/details/122270533