zoukankan      html  css  js  c++  java
  • Permutations

     1 public class Solution {
     2     public ArrayList<ArrayList<Integer>> permute(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         permutation(num, 0, len, result);
     8         return result;
     9     }
    10     
    11     public void permutation(int[] num, int depth, int len, ArrayList<ArrayList<Integer>> result){
    12         if(depth == len){
    13             ArrayList<Integer> per = new ArrayList<Integer>();
    14             for(int i =0 ; i < len; i++)
    15                 per.add(num[i]);
    16             
    17             result.add(per);
    18         }
    19         
    20         for(int i = depth; i < len; i++) {
    21             int tmp = num[i];
    22             num[i] = num[depth];
    23             num[depth] = tmp;
    24             
    25             permutation(num, depth + 1, len, result);
    26             
    27             tmp = num[i];
    28             num[i] = num[depth];
    29             num[depth] = tmp;
    30         }
    31     }
    32 }
  • 相关阅读:
    软件工程—附加作业
    软件工程最终总结
    电梯调度(两人结对)
    VS单元测试
    第二周作业(2,3题)
    VS的安装
    补救
    漂亮男孩不说谎
    博客带我成长
    Java后缀数组-求sa数组
  • 原文地址:https://www.cnblogs.com/jasonC/p/3431183.html
Copyright © 2011-2022 走看看