class Solution(object):
def combinationSum3(self, k, n):
"""
:type k: int
:type n: int
:rtype: List[List[int]]
"""
visit=[True]*9
self.res=[]
def help(k,n,list1,visit):
if k==0 and n==0:
return self.res.append(list1)
if k<=0 or n<=0:
return
for i in range(9):
if visit[i]:
if list1==[] or list1[-1] < i+1:
visit[i]=False
help(k-1,n-1-i,list1+[i+1],visit)
visit[i]=True
help(k,n,[],visit)
return self.res
python leetcode 216. Combination Sum III
最新推荐文章于 2020-09-11 09:55:35 发布