daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Nov 15th, 2018 93 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. class Solution(object):
  2.     def combinationSum(self, candidates, target):
  3.         """
  4.         :type candidates: List[int]
  5.         :type target: int
  6.         :rtype: List[List[int]]
  7.         """
  8.         result = []
  9.         combinations = []
  10.        
  11.         if(candidates == [] or len(candidates) == 0):
  12.             return result
  13.        
  14.         candidates.sort()
  15.        
  16.         self.findTarget(result,combinations,candidates,target,0)
  17.         return result
  18.    
  19.     def findTarget(self, result, combinations, candidates, target, index):
  20.         print(target, combinations)
  21.         if(target == 0):
  22.             result.append(combinations)
  23.             return
  24.        
  25.         for i in range(index,len(candidates)):
  26.             if(candidates[i] > target):
  27.                 break
  28.             combinations.append(candidates[i])
  29.             self.findTarget(result, combinations, candidates, target - candidates[i], i)
  30.             combinations.pop()
  31.         return
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top