One line 35ms(beats 100%) python solution making using of itertools.combinations.

  • 1

    Very efficient although not really an algorithmic solution.

    def combinationSum3(self, k, n):
            return [item for item in itertools.combinations([i for i in xrange(1,10)],k) if sum(item) == n]

  • 0

    Well, it is cheating, but good idea:)

Log in to reply

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