[LeetCode] Permutations
来源:互联网 发布:美橙互联数据库主机名 编辑:程序博客网 时间:2024/06/07 12:10
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]
.
class Solution {public: vector<vector<int> > ans; vector<int> v; bool *nums; int len; vector<vector<int> > permute(vector<int> &num) { len = num.size(); nums = new bool[len]; for(int i = 0;i < len;i ++) nums[i] = true; dfs(num); return ans; } void dfs(vector<int> &num){ if(v.size() == len){ ans.push_back(v); return; } for(int i = 0;i < len;i ++){ if(nums[i]){ v.push_back(num[i]); nums[i] = false; dfs(num); nums[i] = true; v.pop_back(); } } }};
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
- Linux命令行(console)屏幕分辨率调整
- Struts2中的Action
- centos6.5 firefox升级 flash player安装 adblock plus广告屏蔽插件安装
- 成员函数的重载、覆盖与隐藏
- Java网络
- [LeetCode] Permutations
- 零基础学习嵌入式开发以及项目实战开发【火热招募ing】
- 《Java编程思想》第11章 持有对象
- 《Java编程思想》第18章 Java I/O系统
- OpenGL学习日记-2014.11.26--简单裁剪
- 《Java编程思想》第9章 接口
- 【JS】【客户端】在HTML里嵌入JavaScript
- powershell脚本配置jdk环境变量
- Spring的依赖注入