LintCode:数字组合
来源:互联网 发布:it分销商 编辑:程序博客网 时间:2024/05/29 12:17
LintCode:数字组合
回溯算法,注意在最后要清除上一次的状态。
import copyclass Solution: # @param candidates, a list of integers # @param target, integer # @return a list of lists of integers def combinationSum(self, candidates, target): # write your code here self.ans = [] candidates = sorted(list(set(candidates))) res = [] self.my_combinationSum(candidates, res, target, 0) return self.ans def my_combinationSum(self, candidates, res, target, tmp_sum): if tmp_sum > target: return if tmp_sum == target: if sorted(res) not in self.ans: self.ans.append(copy.copy(sorted(res))) return for index in range(0, len(candidates)): res.append(candidates[index]) tmp_sum += candidates[index] self.my_combinationSum(candidates, res, target, tmp_sum) tmp_sum -= candidates[index] res.pop()
0 0
- LintCode-数字组合 II
- lintcode-数字组合-135
- LintCode:数字组合
- LintCode:数字组合 II
- lintcode ----数字组合
- LintCode: 数字组合 II
- LintCode:数字组合
- 数字组合II-lintcode
- lintcode--数字组合
- lintcode -- 数字组合II
- 数字组合-LintCode
- [Lintcode] #135 数字组合
- lintcode--数字组合Ⅱ
- lintcode-数字组合II-153
- [Lintcode] #153 数字组合 II
- LINTCODE——数字组合,数字组合II
- LintCode 135-数字组合 回溯法
- lintcode(153)数字组合 II
- SVN的安装使用
- Redis,Memcache的区别
- 漫步微积分三十五——弧长
- Java中多态性
- LG 的数学计划 ---- 第二步 进制转换
- LintCode:数字组合
- OKHttp源码解析
- 栈的模拟 之 健身馆 (c语言/c++编程)
- ruminations on c++ 沉思录 源代码
- 服务器减压
- LeetCode解题报告 1. Two Sum[easy]
- 创意多会影响关键词的质量度吗?
- Java的反射机制
- 自定义view控件之TextView可以包含两种不同的字体风格