LeetCode题解:Permutations I and II
来源:互联网 发布:企业网络营销策划报告 编辑:程序博客网 时间:2024/05/08 01:49
Permutations
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]
.
Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.
For example,[1,1,2]
have the following unique permutations:[1,1,2]
, [1,2,1]
, and [2,1,1]
.
思路:
反复生成permutation即可。生成permutation的思路可以看这里。当然题解里就用std::next_permutation作弊了。
题解:
class Solution {public: vector<vector<int> > permuteUnique(vector<int> &num) { vector<vector<int>> ret; sort(begin(num), end(num)); ret.push_back(num); while(next_permutation(begin(num), end(num))) ret.push_back(num); return ret; }};
- LeetCode题解:Permutations I and II
- LeetCode Permutations I && II
- [LeetCode][I]Permutations II
- leetcode: Permutations I II
- [LeetCode] Permutations I, II
- LeetCode | Permutations I,II
- Leetcode: Permutations and Permutations II
- leetcode-permutations and permutations II
- LeetCode题解:Subsets I and II
- LeetCode题解:Single Number I and II
- LeetCode题解:Spiral Matrix I and II
- LeetCode题解:Path Sum I and II
- LeetCode题解:N-Queens I and II
- LeetCode题解:Word Break I and II
- LeetCode题解:Combination Sum I and II
- LeetCode题解:Path Sum I and II
- leetcode 46-Permutations and 47-Permutations II
- [Leetcode]Permutations and Permuations II
- 细说Servlet 会话技术介绍
- 关于有无符号数
- 细说Servlet Cookie
- Data Mining Week2 - L1
- 洒出
- LeetCode题解:Permutations I and II
- The first time to exercise the convolution
- 细说Servlet 保存会话的技术 Session
- Ubuntu 12.04 安装VMware Player 6.0
- Sublime Text 2.02注册码
- centos关机与重启命令详解
- Data Mining Week2 - L2 ROC方法二元分
- linux磁盘分区fdisk命令详解
- 离群点检测方法综述