1 line Python solution using itertools libary


  • 0
    B
    import itertools
    
    class Solution(object):
        def combinationSum3(self, k, n):
            """
            :type k: int
            :type n: int
            :rtype: List[List[int]]
            """
            return [c for c in itertools.combinations(range(1,10), k) if sum(c) == n]
    

Log in to reply
 

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