LeetCode 46 - Permutations
来源:互联网 发布:Java加密解密 面试 编辑:程序博客网 时间:2024/05/27 06:53
Permutations
Given a collection of distinct 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]
.
My Code
class Solution {public: void doPermute(vector<vector<int> >& res, vector<int> r, vector<int> v) { int size = v.size(); if (size == 1) { r.push_back(v[0]); res.push_back(r); return; } for (int i = 0; i < size; i++) { vector<int> rr(r); vector<int> vv(v); rr.push_back(v[i]); vv.erase(vv.begin() + i); doPermute(res, rr, vv); } } vector<vector<int> > permute(vector<int>& nums) { vector<vector<int> > res; vector<int> r; vector<int> v(nums); doPermute(res, r, v); return res; }};Runtime: 20 ms
0 0
- LeetCode 46 Permutations + LeetCode 47 Permutations II
- LeetCode 46: Permutations
- leetcode 46 Permutations
- LeetCode 46 Permutations II
- LeetCode(46) Permutations
- [leetcode 46] Permutations
- Leetcode NO.46 Permutations
- leetcode || 46、Permutations
- leetcode-46 Permutations
- leetcode 46 : Permutations
- Leetcode #46 Permutations
- LeetCode(46) Permutations
- leetcode 46: Permutations
- [leetcode-46]Permutations(java)
- LeetCode(46)Permutations
- [Leetcode]#46 Permutations
- leetcode 46:Permutations
- 【leetcode】【46】Permutations
- Min-Min算法 Max-Min算法
- Slack 完整教學與上手心得:找到正確的團隊溝通之道
- 90、setStatusBarStyle无效问题 修改状态栏颜色 只有白色黑色可选UIStatusBarStyleLightContent
- js 解析 json
- C++ 调试技巧
- LeetCode 46 - Permutations
- Android TV如何杀死后台正在播放的媒体应用。。。
- Animation代码设置
- zzuoj 10403: D.山区修路 【线段树优化dp】
- android环境搭建
- angularjs 关于ui-router分层使用
- android 无线调试
- 【错误总结】makefile的编写问题:一定要注意不能有随随便便的tab、空格等
- 关于从eclipse部署已经发布到Android studio的坑