题解 | #和为S的连续正数序列#
和为S的连续正数序列
https://www.nowcoder.com/practice/c451a3fd84b64cb19485dad758a55ebe
function FindContinuousSequence(sum) { // write code here if(sum<=0) return []; let seqs=[]; let n=2; while(n**2+n<=2*sum){ let n0=(2*sum+n-n**2)/(2*n); if(Number.isInteger(n0)){ let seq=[]; for(let i=0;i<n;i++) seq.push(n0+i); seqs.unshift(seq); } n++; } return seqs; } module.exports = { FindContinuousSequence : FindContinuousSequence };
JavaScript解法