给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。
candidates 中的每个数字在每个组合中只能使用一次。
思路,紧接上题,一开始想修改
self.dfs(nums,target-nums[i],i+1,temp+[nums[i]],res)
重复元素报错,解决,判断temp在不在res中:
if target == 0 and temp not in res:
优化:
if i > index and nums[i]==nums[i-1]:
continue