zoukankan      html  css  js  c++  java
  • 排列组合算法

    public class Solution{
        public List<List<Integer>> permutations(int[] arr){
            List<List<Integer>> res = new ArrayList<List<Integer>>();
            //corner
            if ( arr == null || arr.length == 0 ){
                return res;
            }

            //core
            List<Integer> curList = new ArrayList<>();

            helper(res, curList, arr);

            return res;
        }


        public void helper(List<List<Integer>> res, List<Integer> curList, int[] arr){
            //base
            if ( curList.size() == arr.length ){
                res.add(new ArrayList<Integer>(curList));           
                return ;
            }

            //current
            for ( int i = 0; i < arr.length; i++ ){
                if ( curList.contains(arr[i]) ){
                    continue;
                }

                curList.add(arr[i]);

                //next
                helper(res, curList, arr);

                curList.remove(curList.size() - 1);                   
            }
        }
    }

  • 相关阅读:
    OCP-1Z0-052-V8.02-28题
    OCP-1Z0-052-V8.02-27题
    OCP-1Z0-052-V8.02-26题
    OCP-1Z0-052-V8.02-25题
    Oracle DB 管理还原数据
    Flex中常见的图
    OCP-1Z0-052-V8.02-23题
    OCP-1Z0-052-V8.02-21题
    OCP-1Z0-052-V8.02-20题
    OCP-1Z0-052-V8.02-19题
  • 原文地址:https://www.cnblogs.com/energy1010/p/6867799.html
Copyright © 2011-2022 走看看