TLE issue, need some modification for my codes.


  • 0
    W
    class Solution:
    # @param candidates, a list of integers
    # @param target, integer
    # @return a list of lists of integers
    def __init__(self):
        self.aStack = []
    
    def combinationSum(self, candidates, target):
        
        self.combinationSumCal(candidates, target)
        return [list(i) for i in set(map(tuple, map(sorted, self.aStack)))]
    def combinationSumCal(self, candidates, target, bStack = []):
        for i in candidates:
            cStack = bStack[:]
            if target - i == 0:
                cStack.append(i)
                self.aStack.append(cStack)
            elif target > i:
                cStack.append(i)
                self.combinationSumCal(candidates, target - i, cStack)
            else:
                continue
    

    i got TLE from this line i guess. [list(i) for i in set(map(tuple, map(sorted, self.aStack)))]

    so what should i do to pass this question?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.