Skip to content

Latest commit

 

History

History
45 lines (31 loc) · 930 Bytes

77-combinations.md

File metadata and controls

45 lines (31 loc) · 930 Bytes

77. Combinations - 组合

给定两个整数 nk,返回 1 ... n 中所有可能的 k 个数的组合。

示例:

输入: n = 4, k = 2
输出:
[
  [2,4],
  [3,4],
  [2,3],
  [1,2],
  [1,3],
  [1,4],
]

题目标签:Backtracking

题目链接:LeetCode / LeetCode中国

题解

Language Runtime Memory
python3 196 ms N/A
class Solution:
    def combine(self, n, k):
        """
        :type n: int
        :type k: int
        :rtype: List[List[int]]
        """
        return list(itertools.combinations(range(1, n+1), k))