leetcode72:combinations
题目描述
[↵ [2,4],↵ [3,4],↵ [2,3],↵ [1,2],↵ [1,3],↵ [1,4],↵]
For example,
If n = 4 and k = 2, a solution is:
[↵ [2,4],↵ [3,4],↵ [2,3],↵ [1,2],↵ [1,3],↵ [1,4],↵]↵
输出
[[1],[2],[3]]
class Solution {
public:
/**
*
* @param n int整型
* @param k int整型
* @return int整型vector<vector<>>
*/
void DFS(vector <vector<int> >&ret,vector<int> &path,int n,int start,int rest){
if (!rest)
ret.push_back(path);
else {
for (int i=start;i<=n-rest+1;++i){
path.push_back(i);
DFS(ret,path,n,i+1,rest-1);
path.pop_back();
}
}
}
vector<vector<int> > combine(int n, int k) {
// write code here
vector <vector<int>> ret;
vector<int> path;
DFS(ret,path,n,1,k);
return ret;
}
};
leetcode72:combinations的更多相关文章
- Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...
- [LeetCode] Factor Combinations 因子组合
Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a func ...
- [LeetCode] Combinations 组合项
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...
- [LeetCode] Letter Combinations of a Phone Number 电话号码的字母组合
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- Leetcode 254. Factor Combinations
Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a func ...
- 17. Letter Combinations of a Phone Number
题目: Given a digit string, return all possible letter combinations that the number could represent. A ...
- LeetCode——Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- Combination Sum II Combinations
https://leetcode.com/problems/combination-sum-ii/ 题目跟前面几道题很类似,直接写代码: class Solution { public: vector ...
- No.017:Letter Combinations of a Phone Number
问题: Given a digit string, return all possible letter combinations that the number could represent.A ...
随机推荐
- 使用 PL/SQL Developer 导入 .sql 文件
操作系统:Windows 10 x64 PL/SQL Developer Version 12.0.7.1837 (64 bit) 01.226959 第一节:下载 Oracle Database X ...
- vue点击切换样式,点击切换地址栏,点击显示或者隐藏
1. vue点击显示切换 :class='{"span":index==0}' class原本是 类选择器 加上 :class就是绑定属性的意思 '{"span" ...
- 测试AAA
程序计数器(线程私有) 程序计数器(Program Counter Register),也有称作为 PC 寄存器.保存的是程序当 前执行的指令的地址(也可以说保存下一条指令的所在存储单元的地址),当 ...
- vs code个性化设置
文件=>首选项=>设置,直接在搜索栏搜索有背景色的部分即可 1. 鼠标滚轮缩放 "editor.mouseWheelZoom": true 2. 显示空格和tab符号 ...
- lora网关
lora网关 lora物联网网关ZLAN9743可以实现RS232/485/422/以太网转 LoRa功能 是一款高性价比远距离无线通讯网关.LoRa和GPRS.4G方案相比它无需入网月租费,和Wif ...
- Linux系统编程 —线程同步概念
同步概念 同步,指对在一个系统中所发生的事件之间进行协调,在时间上出现一致性与统一化的现象. 但是,对于不同行业,对于同步的理解略有不同.比如:设备同步,是指在两个设备之间规定一个共同的时间参考:数据 ...
- 原生js实现一个自定义下拉单选选择框
浏览器自带的原生下拉框不太美观,而且各个浏览器表现也不一致,UI一般给的下拉框也是和原生的下拉框差别比较大的,这就需要自己写一个基本功能的下拉菜单/下拉选择框了.最近,把项目中用到的下拉框组件重新封装 ...
- centos8平台使用ethtool配置网卡
一,ethtool命令所属的包 [root@centos8 liuhongdi]# whereis ethtool ethtool: /usr/sbin/ethtool /usr/share/man/ ...
- 从零开始针对 .NET 应用的 DevOps 运营实践 - Jenkins & SonarQube 安装配置
一.Overview 继续 DevOps 实施的相关内容,在上一篇的博客中,完成了对于工具链中使用到的软件所需的运行环境的配置,在这一篇的博客中,将聚焦于我们使用到的两个主要的软件:Jenkins 与 ...
- Linux基础命令列表
命令列表 A alias apt apt-get arp -n -s arping ab B bc basename bash -n -x bzip2 bunzip2 bzcat blkid brct ...