Three lines simple python recursive solution


  • 0
    S
    class Solution(object):
        def combine(self, n, k):
            """
            :type n: int
            :type k: int
            :rtype: List[List[int]]
            """
            if n < k or k == 0:
                return []
            return self.combine(n-1,k) + map(lambda r:r+[n], self.combine(n-1,k-1) or [[]])

Log in to reply
 

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