leetcode-Permutations
来源:互联网 发布:认识数据库管理 编辑:程序博客网 时间:2024/06/12 00:34
Difficulty: Medium
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 { vector<vector<int> > res; void helper(vector<int> &nums,int n,int cur){ if(cur==n){ res.push_back(nums); return; } for(int i=cur;i<n;++i){ if(cur!=i) swap(nums[cur],nums[i]); helper(nums,n,cur+1); if(cur!=i) swap(nums[cur],nums[i]); } }public: vector<vector<int>> permute(vector<int>& nums) { if(nums.empty()) return res; helper(nums,nums.size(),0); 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
- 20条Linux命令面试问答
- IT人生
- 《剑指offer》——构建乘积数组
- java提取字符串中的汉字
- Effective C++ 笔记 第二部分 构造/析构/赋值运算
- leetcode-Permutations
- Unity-APk 错误:Error building Player: Couldn't build player because of unsupported data on target plat
- android中handle的用法
- char数组与char指针的区别与联系
- iOS获取汉字首字母
- 做一个有价值的软件开发者
- python IDE:PyCharm简介
- iOS获取汉字首字母
- Spark 入门之四:Spark任务调度架构