LeetCode--46. Permutations
来源:互联网 发布:知乎 扒皮 编辑:程序博客网 时间:2024/06/08 09:13
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], [3,2,1]]
解题代码:
class Solution {public: vector<vector<int>> permute(vector<int>& nums) { vector<vector<int>> res;//结果 vector<bool> temp(nums.size(), false);//标志 vector<int> resm;//单个结果 permute(nums, res, temp, resm); return res; }private: void permute(vector<int>& nums, vector<vector<int>>& res, vector<bool> temp, vector<int> resm){ if(resm.size() == nums.size()) { res.push_back(resm); } else { for(int i = 0; i < nums.size(); i++) { if(temp[i] == true) continue; resm.push_back(nums[i]); temp[i] = true; permute(nums, res, temp, resm); temp[i] = false; resm.pop_back(); } } }};
阅读全文
0 0
- [LeetCode]46.Permutations
- LeetCode 46.Permutations
- 46. Permutations Leetcode Python
- LeetCode --- 46. Permutations
- [Leetcode] 46. Permutations
- [leetcode] 46.Permutations
- LeetCode 46. Permutations DFS
- 46. Permutations LeetCode
- Leetcode 46. Permutations
- leetcode 46. Permutations
- LeetCode *** 46. Permutations
- LeetCode 46. Permutations
- leetcode 46. Permutations
- LeetCode - 46. Permutations
- 【leetcode】46. Permutations
- leetcode 46. Permutations
- [LeetCode] 46. Permutations
- leetcode 46. Permutations
- Retrofit:打造自己的Converter之byte[]
- POJ 1848 Tree 笔记
- 在win7,pycharm编译器下配置第一个django程序
- 【实训】Android中xml动画定义
- 计算几何练习2
- LeetCode--46. Permutations
- 关于indexOf的巧妙使用
- 使用命令行编译QT helloworld 项目
- 整洁即是正义
- linux磁盘检测和修复
- 软raid5+lvm步骤
- 编辑器 兼容微信
- 辣鸡数据结构作业:简易银行管理系统
- lintcode/leetcode由易至难第15题:Merge Two Binary Trees