Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution(object):
- def current(candidates, ctree):
- path = ctree[1]
- new = []
- count = 0
- for lchild in ctree[0]:
- for sub in candidates[count:]:
- add = []
- if (lchild[0]-sub) > 0:
- add += [lchild[0] - sub]
- add[1:] = lchild[1:]
- add += [sub]
- new += [add]
- if lchild[0]-sub == 0:
- path += [lchild[1:] + [sub] ]
- else:
- pass
- count += 1
- return [new, path]
- def combinationSum(self, candidates, target):
- if isinstance(target, int):
- tree = [[[target]],[]]
- else:
- tree = target
- start = [candidates, tree]
- test = current(candidates, tree)
- if test[0] == []:
- return tree[1]
- else:
- combinationSum(candidates, test)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement