LeetCode(46) Permutations
来源:互联网 发布:四万亿 知乎 编辑:程序博客网 时间:2024/05/17 11:57
深度优先搜索算法设计技术。
class Solution {public: void dfs(vector<int> nums, vector<int> &oneResult, int depth, int &length, vector<vector<int>> &result) { if(depth == length - 1) { oneResult[depth] = nums[0]; result.push_back(oneResult); return; } for(int i = 0; i < nums.size(); i++) { oneResult[depth] = nums[i]; vector<int> numsTmp(nums); numsTmp.erase(numsTmp.begin() + i); dfs(numsTmp, oneResult, depth + 1, length, result); } } vector<vector<int>> permute(vector<int>& nums) { sort(nums.begin(), nums.end()); int length = nums.size(); vector<int> oneResult(length, 0); vector<vector<int>> result; int depth = 0; dfs(nums, oneResult, depth, length, result); return result; }};
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
- 惊叹计算机执行速度的提升---以n Queens 问题为例
- cocos2dx中的游戏储存-UserDefault
- FindBugs 错误信息汇总
- eclipse svn滤过不需要提交的文件和文件夹
- 拷贝构造函数
- LeetCode(46) Permutations
- Matlab分析证券相关系数
- Qt GUI 通过鼠标事件剖析整个事件处理流程(基于Qt4.5.2源码windows平台)
- android技术 面试题 笔试题精华重点
- iOS动画集合
- Android四大基本组件介绍与生命周期
- ubuntu 12.04下编译安装nginx-1.9.3
- 关于XShell上登录跳板机问题及第七天实习记录
- Linux内核Socket参数调优