递归中return的作用
这是leetcode 组合总和的题,我使用递归写完之后,发现有重复的,python的set()无法直接对二维表进行set,有人直接加了一条return就达到了目的,不太理解,请问一下class Solution(object):
def combinationSum(self, candidates, target):
"""
:type candidates: List[int]
:type target: int
:rtype: List[List[int]]
"""
candidates.sort()
res = []
ans = []
(target,candidates,0,res,ans)
print(res)
return res
def compute(self,target,candidates,start,result,answer):
for i in range(start,len(candidates)):
if target > 0:
answer.append(candidates[i])
(target-candidates[i],candidates,i,result,answer)
answer.pop()
if target < 0:
pass
if target == 0:
tmp = answer[:]
result.append(tmp)
return
请问这里return怎么起到了去重的作用