LeetCode--Combinations
来源:互联网 发布:金山软件框架 编辑:程序博客网 时间:2024/06/09 21:05
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.
For example,
If n = 4 and k = 2, a solution is:
[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]
#include<vector>using std::vector;class Solution {public:vector<vector<int> > combine(int n, int k) {vector<vector<int>> res;vector<int> temp(k,0);get_res(0,0,k,n,res,temp);return res;}void get_res(int data,int now, int k, int n, vector<vector<int>>& res, vector<int>& temp){if(k == now){res.push_back(temp);return;}for(int i = data+1; i <= n-k+now+1; i++){temp[now] = i;get_res(i,now+1,k,n,res,temp);}return;}};
0 0
- LeetCode: Combinations
- LeetCode: Combinations
- LeetCode Combinations
- [Leetcode] Combinations
- [LeetCode] Combinations
- Leetcode: Combinations
- LeetCode Combinations
- [Leetcode] Combinations
- [Leetcode] Combinations
- [leetcode] Combinations
- [LeetCode]Combinations
- [leetcode]Combinations
- LeetCode-Combinations
- [leetcode] Combinations
- LeetCode - Combinations
- 【Leetcode】Combinations
- Leetcode: Combinations
- 【leetcode】Combinations
- poj 2456 Aggressive cows(贪心+二分)
- org.springframework.web.servlet.handler.SimpleUrlHanderMapping异常处理
- 经典的kmp算法教程
- iOS摄像头和相册-UIImagePickerController-浅析
- 【Cocos2d-x】PhysicsEditor的使用
- LeetCode--Combinations
- 【数据结构课程设计】信管1133何景涛201311671308
- 网络协议栈和tcpdump抓包练习
- c++学生管理系统(STL)
- 子子撰足椎撞踪壮专拽尊拽醉尊桌状作庄
- 宗走装足锥渍纵注拙足撞揍纵综嘴醉追锥
- DES加密算法笔记
- 黑马程序员——Java之面向对象
- 砖资踪祖拽尊孜昨宗子踪拙状孜座昨组驻