算法随想录算法训练营第二十五天| 491.递增子序列 46.全排列47.全排列 II

491.递增子序列

class Solution {
    List> lists = new ArrayList<>();
    public List> findSubsequences(int[] nums) {
        List list = new ArrayList<>();
        backTracking(nums,list,0);
        return lists;
    }

    public void backTracking(int[] nums,List list,int start){
        if(list.size() >= 2){
            lists.add(new ArrayList<>(list));
        }
        Set set = new HashSet<>();
        for(int i = start;i

46.全排列

class Solution {
    List> lists = new ArrayList<>();
    public List> permute(int[] nums) {
        List list = new ArrayList<>();
        boolean[] temp = new boolean[nums.length];
        backTracking(list,nums,temp);
        return lists;
    }

    public void backTracking(List list,int[] nums,boolean[] temp){
        if(list.size() == nums.length){
            lists.add(new ArrayList<>(list));
            return;
        }
        for(int i = 0;i

47.全排列 II

class Solution {
    List> lists = new ArrayList<>();
    public List> permuteUnique(int[] nums) {
        List list = new ArrayList<>();
        Arrays.sort(nums);
        boolean[] temp = new boolean[nums.length]; 
        backTracking(nums,0,list,temp);
        return lists;
    }

    public void backTracking(int[] nums,int start,List list,boolean[] temp){
        if(list.size() == nums.length){
            lists.add(new ArrayList<>(list));
            return;
        }
        for(int i = 0;i

你可能感兴趣的:(算法,windows)