[leetcode] Permutations
来源:互联网 发布:上瘾网络剧见面会视频 编辑:程序博客网 时间:2024/04/30 23:06
Permutations
Total Accepted: 5072 Total Submissions: 16450
Given a collection of numbers, return all possible permutations.For example,
[1,2,3] have the following permutations:
[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].
参考
http://www.geeksforgeeks.org/write-a-c-program-to-print-all-permutations-of-a-given-string/
class Solution {
public:
void dfs(vector<int> &num, int step, vector<vector<int> > &res) {
if (step > num.size()-1) {
res.push_back(num);
return;
}
int i;
for (i = step; i < num.size(); i++) {
swap(num[i], num[step]);
dfs(num, step + 1, res); // 注意别写成step++了。。。 回溯回不来了。。
swap(num[i], num[step]);
}
}
vector<vector<int> > permute(vector<int> &num) {
vector<vector<int> > res;
dfs(num, 0, res);
return res;
}
};
0 0
- 【LeetCode】Permutations && Permutations II
- leetcode: Permutations/Permutations II
- leetcode Permutations & Permutations II
- [Leetcode]Permutations && Permutations II
- LeetCode: Permutations
- LeetCode: Permutations
- [Leetcode] Permutations
- [LeetCode] Permutations
- Leetcode: Permutations
- [Leetcode] Permutations
- [Leetcode] Permutations
- [LeetCode]Permutations
- LeetCode-Permutations
- [leetcode] permutations
- LeetCode - Permutations
- Leetcode: Permutations
- 【leetcode】Permutations
- 【LeetCode】Permutations
- 个别习惯使用的allegro快捷键
- 开启win7的无线AP功能
- 林口seo优化:如何写出高质量的文章
- 正向代理/反向代理/透明代理
- setDefaultCloseOperation(int operation)
- [leetcode] Permutations
- python 格式化时间字符串
- 用Python让树莓派“说话”
- 版本控制系统概述
- 鼠标悬浮时菜单效果
- 标准库vector类型简介
- mobiscroll 触屏日期插件
- Android中Bitmap, Drawable, Byte,ID之间的转化
- 关于读取工程根目录下的文件的方法