//剑指 Offer 57 - II.和为s的连续正数序列
class Solution {
public:
vector<vector<int>> findContinuousSequence(int tar) {
int x;
vector<vector<int>>ans;
for (int i = 2;; i++) {
x = tar * 2;
if (x % i) continue;
x = x / i - i + 1;
if (x <= 0) break;
if (x % 2) continue;
x /= 2;
vector<int>t;
while (t.size() < i)
t.emplace_back(x++);
ans.emplace_back(t);
}
reverse(ans.begin(), ans.end());
return ans;
}
};
LeetCode剑指 Offer 57 - II. 和为s的连续正数序列
最新推荐文章于 2024-08-20 21:31:52 发布