3 lines,Recursion,Python solution.32 ms (Why down ...)

  • 0

    Add a new parameter b--means begin number.
    The range of x is : [ b,11-k )

    def combinationSum3(self, k, n,b=1):
        if k == 1: 
            return (b <= n < 10) * [[n]]  
        return [[x] + r for x in range(b, 11-k) 
                        for r in self.combinationSum3(k-1, n-x, x+1)]

Log in to reply

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