zoukankan      html  css  js  c++  java
  • Permutations II

     1 public class Solution {
     2     public ArrayList<ArrayList<Integer>> permuteUnique(int[] num) {
     3         // IMPORTANT: Please reset any member data you declared, as
     4         // the same Solution instance will be reused for each test case.
     5         int len = num.length;
     6         ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
     7         HashSet<ArrayList<Integer>> tmpResult = new HashSet<ArrayList<Integer>>();
     8         permutation(num, 0, len, result, tmpResult);
     9         return result;
    10     }
    11     
    12     public void permutation(int[] num, int depth, int len, ArrayList<ArrayList<Integer>> result, HashSet<ArrayList<Integer>> tmpResult){
    13         
    14         if(depth == len){
    15             ArrayList<Integer> per = new ArrayList<Integer>();
    16             for(int i =0 ; i < len; i++)
    17                 per.add(num[i]);
    18                 
    19             if(tmpResult.add(per))
    20                 result.add(per);
    21         }
    22         
    23         for(int i = depth; i < len; i++) {
    24             if(i != depth && num[i] == num[depth])
    25                 continue;
    26 
    27             int tmp = num[i];
    28             num[i] = num[depth];
    29             num[depth] = tmp;
    30             
    31             permutation(num, depth + 1, len, result, tmpResult);
    32             
    33             tmp = num[i];
    34             num[i] = num[depth];
    35             num[depth] = tmp;
    36         }
    37     }
    38 }
  • 相关阅读:
    Metasploit的使用命令_1
    Kali Linux -系统定制
    20200522随笔
    阿里大于接口的问题
    根据一篇文章学习逻辑漏洞
    flask注册蓝图报错
    python 生成验证码
    flask-mail 机制
    对巡风vulscan的理解
    “百度杯” YeSerCMS
  • 原文地址:https://www.cnblogs.com/jasonC/p/3431213.html
Copyright © 2011-2022 走看看