39. Combination Sum

class Solution:
def combinationSum(self, candidates,target):
result=[]
candidates.sort() # not necessary
self.rec(candidates,0,[],target,result)
return result
def rec(self,candidates,ind,ds,target,result):

if target<0:
return
elif target == 0 :
result.append(ds)
else:
for i in range(ind,len(candidates)):
self.rec(candidates,i,ds+[candidates[i]],target-candidates[i],result)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dhanarajappu

Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.