# -*- coding: utf-8 -*-"""
Created on Fri Dec 17 11:12:35 2021
Function:
@author: 小梁aixj
"""classSolution(object):defcombine(self, n, k):
res =[]
self.get_combine(res,[], n, k,1)return res
defget_combine(self, res, prefix, n, k, start):if k ==0:
res.append(list(prefix))elif start <= n:
prefix.append(start)
self.get_combine(res, prefix, n, k -1, start +1)
prefix.pop()
self.get_combine(res, prefix, n, k, start +1)if __name__=='__main__':
s = Solution()print(s.combine(4,2))
文章目录组合1,程序简介示例:以下程序实现了这一功能,请你填补空白处内容:2,程序代码3,运行结果组合1,程序简介给定两个整数 n 和 k,返回 1 … n 中所有可能的 k 个数的组合。示例:输入: n = 4, k = 2输出:[[2,4],[3,4],[2,3],[1,2],[1,3],[1,4],]以下程序实现了这一功能,请你填补空白处内容:#include <bits/stdc++.h>using namespace std;class Solution