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

和为S的连续正数序列

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

你最爱的双指针

function FindContinuousSequence(sum)
{
    // write code here
    let res=[]
    let i=1
    let j=2
    for(i,j;i<j;){
        let tmp=(i+j)*(j-i+1)/2
        if(tmp===sum){
            let tmpArray=[]
            for(let q=i;q<=j;q++){
                tmpArray.push(q) 
            }
            res.push(tmpArray)
            i++
        }else if(tmp <sum){
            j++
        }else{
            i++
        }  
    }
    return res
}
module.exports = {
    FindContinuousSequence : FindContinuousSequence
};
全部评论

相关推荐

只写bug的程序媛:才15,我招行20多万,建设银行50多万,说放弃就放弃
点赞 评论 收藏
分享
02-15 15:29
青岛大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务