题解 | #和为S的连续正数序列#

和为S的连续正数序列

https://www.nowcoder.com/practice/c451a3fd84b64cb19485dad758a55ebe

class Solution {
public:
    vector<vector<int> > FindContinuousSequence(int sum) {
        vector<vector<int> > res;
        vector<int> temp;
        int i = 1;
        while(i + i + 1 <= sum){
            int t = 0;
            for(int j = i;t < sum;j++){
                t += j;
                temp.push_back(j);
                if(t == sum) res.push_back(temp);
            }
            temp.clear();
            i++;
        }
        return res;
    }
};//时间复杂度O √n

全部评论

相关推荐

双尔:反手回一个很抱歉,经过慎重考虑,您与我的预期暂不匹配,感谢您的投递
点赞 评论 收藏
分享
hwwhwh:同双非,有大厂实习其实也没啥用,主要看运气,等就行了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务