zoukankan      html  css  js  c++  java
  • 47. Permutations II

    public class Solution {
        public List<List<Integer>> permuteUnique(int[] nums) {
            List<List<Integer>> ret=new ArrayList<List<Integer>>();
            Arrays.sort(nums);
            boolean[] used=new boolean[nums.length];
            permute(new ArrayList<Integer>(), used, ret, nums);
            return ret;
        }
        private void permute(List<Integer> list, boolean[] used, List<List<Integer>> ret, int[] nums){
            if(list.size()==nums.length)
                ret.add(new ArrayList<Integer>(list));
            else
                for(int i=0;i<nums.length;i++)
                    if(used[i]==false)
                    {
                        if(i>0&&nums[i]==nums[i-1]&&used[i-1]==false)
                            continue;
                        used[i]=true;
                        list.add(nums[i]);
                        permute(list, used, ret, nums);
                        list.remove(list.size()-1);
                        used[i]=false;
                    }
        }
    }
  • 相关阅读:
    列表、元组、字符串的相互转化
    python中的常用BIF
    python中的类型
    python内置模块
    打印字体颜色整理
    xml操作
    内置函数
    迭代器
    装饰器
    函数
  • 原文地址:https://www.cnblogs.com/asuran/p/7590217.html
Copyright © 2011-2022 走看看