leetcode Permutations II
来源:互联网 发布:淘宝联盟网站推广位 编辑:程序博客网 时间:2024/05/27 20:50
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]
.
原题:点击打开链接
class Solution {private: bool nextPermutation(vector<int> &num){ int index, size = num.size(), swapIndex; for(index = size - 2; index >= 0 && num[index] >= num[index + 1]; index--); if(num[index] >= num[index + 1]){ return false; } for(swapIndex = size - 1; num[swapIndex] <= num[index]; swapIndex--); swap(num[swapIndex], num[index]); for(++index,--size; index<size; swap(num[index++], num[size--])); return true; }public: vector<vector<int> > permuteUnique(vector<int> &num) { vector<vector<int> > ans; sort(num.begin(), num.end()); do{ ans.push_back(num); }while(nextPermutation(num)); return ans; }};
0 0
- 【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
- [leetcode] Permutations II
- Girl_iOS100天学iOS的第十一天(流水日记一篇)
- asp.net C#母版页和内容页事件排版加载顺序生命周期
- poj 1759 Garland 二分搜索
- Verilog状态机详谈
- ASP.NET动态网站开发培训-39.互动论坛制作(七、制作回复留言页面)
- leetcode Permutations II
- 聪明的kk(南阳oj171)(dp固定终点的最长路)
- 关于smp
- 嵌入式开发学习笔记(1)认识与规划
- Centos7+httpd+fastcgi+rails安装
- 二叉树的非递归遍历
- VC拖放窗口中的控件
- 【hdu】1577 WisKey的眼神(两个点之间是否存在整数坐标)
- Android Studio初体验坎坷路