/** * @param {number}target * @return {number[][]} */ var findContinuousSequence = function (target) { const res = []; for (let i = 1; i < target; i++) { let sum = 0; let tmp = []; for (let j = i; j < target && sum < target; j++) { sum += j; tmp.push(j); } if (sum === target) res.push(tmp); } return res; };
/** * @param {number}target * @return {number[][]} */ var findContinuousSequence = function (target) { if (target.length < 2) return []; let start = 1; let end = 2; const res = []; while (end <= Math.ceil(target / 2) && start < end) { let sum = 0; for (let i = start; i <= end; i++) { sum += i; } if (sum === target) { let tmp = []; for (let i = start; i <= end; i++) { tmp.push(i); } res.push(tmp); } if (sum < target) { end++; } else { start++; } } return res; };