leetcode Permutations II
来源:互联网 发布:淘宝关键词查询 编辑:程序博客网 时间:2024/06/10 17:17
Permutations II原题地址:
https://oj.leetcode.com/problems/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]
.
public class Solution { List<List<Integer>> list = new ArrayList<List<Integer>>();public List<List<Integer>> permuteUnique(int[] num) {if (num == null || num.length == 0)return list;Arrays.sort(num);boolean[] check = new boolean[num.length];LinkedList<Integer> temp = new LinkedList<Integer>();permutelist(num, check, temp, 0);return list;}private void permutelist(int[] num, boolean[] check, LinkedList<Integer> temp, int p) {if (p == num.length) {LinkedList<Integer> plist = (LinkedList<Integer>) temp.clone();list.add(plist);}for (int i = 0; i < num.length; i++) {if (i > 0 && num[i-1] == num[i] && !check[i-1])continue;if (!check[i]) {temp.add(num[i]);check[i] = true;permutelist(num, check, temp, p+1);temp.pollLast();check[i] = false;}}}}
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
- .bash_profile和.bashrc的区别(如何设置生效)
- 练手小项目(2)-生活小助手--身份证查询
- linux 常用网络命令
- 657 - The die is cast
- C语言sscanf和sprintf输入输出使用及Strlen、Memset解释
- leetcode Permutations II
- vs2010(c++)版“hello world”
- hdu1030
- 杭电2030
- startActivity问题
- 用 stack 解决“八皇后问题”
- HDU 1312 Red and Black(深搜)
- iOS 的 APP 在系统中如何适应 iPhone 5s/6/6 Plus 三种屏幕的尺寸?
- Comparable和Comparator的区别