LeetCode 45. Permutations II
来源:互联网 发布:mac系统zh cn 编辑:程序博客网 时间:2024/06/05 17:15
做LeetCode 44. Permutations时,考虑的就是找出所有unique permutations,而且44中也没有考察duplicate的sample, 所以同一份代码都能AC
思路是num排升序,将其加入返回值ret中,再迭代去找它的LeetCode 30. Next Permutation
代码:
class Solution {public: vector<vector<int> > permute(vector<int> &num) {vector<vector<int> > ret;sort(num.begin(), num.end());do {ret.push_back( num );} while( has_next_permutation(num) );return ret;}private:bool has_next_permutation(vector<int>& num){for (int i = num.size()-2; i >= 0; -- i){for (int j = num.size()-1; j > i; -- j){if (num[j] > num[i]){swap(num[i], num[j]);sort(num.begin()+i+1, num.end());return true;}}}return false;}};
0 0
- LeetCode 45. Permutations II
- 【LeetCode】Permutations && Permutations II
- leetcode: Permutations/Permutations II
- leetcode Permutations & Permutations II
- [Leetcode]Permutations && Permutations II
- Leetcode: Permutations and Permutations II
- leetcode-permutations and permutations II
- Leetcode:Permutations与Permutations II
- LeetCode: Permutations II
- LeetCode Permutations II
- LeetCode: Permutations II
- [Leetcode] Permutations II
- [LeetCode] Permutations II
- [Leetcode] Permutations II
- leetcode Permutations II
- [LeetCode]Permutations II
- leetcode - Permutations II
- LeetCode-Permutations II
- 内存分配器 (Memory Allocator)
- RR调度(Round-robin scheduling)简介
- 激活后台窗口
- LeetCode 42. Multiply Strings
- LeetCode 44. Permutations
- LeetCode 45. Permutations II
- developer.biao.daily.20140628
- 大话重构连载2:什么是系统重构
- 计算机中带符号的整数为何采用二进制的补码进行存储
- JAVA中两个专门操作枚举类型的容器类
- 浮点数在内存中的存储方式
- 图的最小生成树(MST)之Prim算法
- java中整数类型的2进制表示
- 现在出现这些政策中心重新注册123