Skip to content

Latest commit

 

History

History
25 lines (23 loc) · 572 Bytes

77.md

File metadata and controls

25 lines (23 loc) · 572 Bytes

题目地址

https://leetcode-cn.com/problems/combinations/

解答

class Solution:
    def combine(self, n, k):
        """
            组合
            给定两个整数 n 和 k,返回 1 ... n 中所有可能的 k 个数的组合。
            输入: n = 4, k = 2
            输出:
            [
              [2,4],
              [3,4],
              [2,3],
              [1,2],
              [1,3],
              [1,4],
            ]
        """
        from itertools import combinations

        return list(combinations(range(1, n + 1), k))