We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
原题链接
先明确,元素可以重复使用,但是组合不能重复。
cur === target
const combinationSum = (candidates, target) => { const res = [] // start: 起点索引 arr: 当前集合 cur: 当前所求之和 const dfs = (start, arr, cur) => { if (cur > target) return if (cur === target) { res.push(arr.slice()) return } for (let i = start; i < candidates.length; i++) { arr.push(candidates[i]) dfs(i, arr, cur + candidates[i]) arr.pop() } } dfs(0, [], 0) return res }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
原题链接
回溯
先明确,元素可以重复使用,但是组合不能重复。
cur === target
时,拷贝 arr 推进结果集。The text was updated successfully, but these errors were encountered: