Python solution with itertools


  • 1
    M
    import itertools
    class Solution(object):
        def combine(self, n, k):
            """
            :type n: int
            :type k: int
            :rtype: List[List[int]]
            """
            if n < k:
                return []
            else:
                return list(itertools.combinations([i for i in range(1,n+1)], k))

Log in to reply
 

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