leetcode-剑指57-II-OK

// language C with STL(C++)
// 剑指57-II
// https://leetcode-cn.com/problems/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof/


class Solution {
public:
    vector<vector<int>> findContinuousSequence(int target) {
    	vector<vector<int>> ans;
    	int i =0, total = 0;
    	while(total<=target){
    		total += ++i;
    	}
    	total -= i--;
    	while(i>=2){
    		int temp = target-total;
    		if(temp%i == 0){
    			vector<int> waibiwaibi;
    			temp = temp/i;
    			for(int j = 1; j<=i; j++)
    				waibiwaibi.push_back(j+temp);
    			ans.push_back(waibiwaibi);
    		}
    		total -= i--;
    	}
    	return ans;
    }
};
posted @ 2021-02-03 15:05  RougeBW  阅读(29)  评论(0编辑  收藏  举报