216Combination Sum III
来源:互联网 发布:沈阳网络系统安全技术 编辑:程序博客网 时间:2024/06/05 10:45
class Solution(object):
def combinationSum3(self, k, n):
"""
:type k: int
:type n: int
:rtype: List[List[int]]
"""
cadicates=[x for x in range(1,10)]
res=[]
line=[]
self.helper(cadicates,k,n,res,line)
return res
def helper(self,cadicates,k,n,res,line):
if len(line)==k:
if n==0:
res.append([x for x in line])
return
for i,x in enumerate(cadicates):
line.append(x)
self.helper(cadicates[i+1:],k,n-x,res,line)
line.pop()
def combinationSum3(self, k, n):
"""
:type k: int
:type n: int
:rtype: List[List[int]]
"""
cadicates=[x for x in range(1,10)]
res=[]
line=[]
self.helper(cadicates,k,n,res,line)
return res
def helper(self,cadicates,k,n,res,line):
if len(line)==k:
if n==0:
res.append([x for x in line])
return
for i,x in enumerate(cadicates):
line.append(x)
self.helper(cadicates[i+1:],k,n-x,res,line)
line.pop()
阅读全文
0 0
- 216 Combination Sum III
- 216Combination Sum III
- leetcode 216: Combination Sum III
- 【Leetcode】Combination Sum III #216
- Leetcode 216 Combination Sum III
- LeetCode(216)Combination Sum III
- leetcode 216: Combination Sum III
- [leetcode] 216 Combination Sum III
- [LeetCode 216] Combination Sum III
- 216 Combination Sum III [Leetcode]
- Leetcode #216 Combination Sum III
- LeetCode 216 Combination Sum III
- 【leetcode】【216】Combination Sum III
- 【LeetCode-216】Combination Sum III
- LeetCode 216 Combination Sum III
- leetcode_c++:Combination Sum III(216)
- LeetCode-216:Combination Sum III
- LeetCode #216: Combination Sum III
- Android开发错误:Error:” ” is not translated in “en” (English) [MissingTranslation]处理方法?
- 好看的彩色二维码
- 金蝶EAS,后台抛出业务异常,中断程序
- 二级下拉框
- vi的使用--使用vi查找和替换
- 216Combination Sum III
- 设计模式-设计准则
- shell expect自动化创建用户,修改密码,多台机器一键免秘钥登录
- 全志R16 PK RK3128(多线程优化)草稿
- 20170601M_USER
- 本地的svn文件/文件夹状态图标
- 转载Qt使用美化UI细节
- Mysql不停止主库做Slave ,mysqldump
- PM2