@qizhu8 to be honest, I still doubt about using sort except using it as for the order for one single answer such as your example, it is better to have [1,1,2] than [1,2,1].

But besides that, the sort is not useful, because the answer [1,1,2] and [1,2,1] will not show twice even not using sort! you could try the custom test case and watch std output. The thought of dfs here is searching with for loop, you will never check the node backward in for loop, so it is strictly removed the duplicates in this way. Also try to check the runtime, there is no difference with and w/o sorting.

In addition, we do not need index parameter, and we can simply use the following solution for easy understanding, faster and remembering:

def combinationSum(self, candidates, target):
"""
:type candidates: List[int]
:type target: int
:rtype: List[List[int]]
"""
res = []
self.rec(candidates,target,[],res)
return res
def rec(self,candidates,target,path,res):
if target < 0:
return
if target == 0:
res.append(path)
return
for i in xrange(len(candidates)):
self.rec(candidates[i:],target-candidates[i],path+[candidates[i]],res)