【leetcode每日刷题】47. Permutations II

https://leetcode.com/problems/permutations-ii/

package leetcode;
/**
 * 有重复元素的排列组合
 * 回溯法
 */
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class num47 {
    public List> permuteUnique(int[] nums) {
        List> res = new ArrayList<>();
        List temp = new ArrayList<>();
        boolean[] use = new boolean[nums.length];
        Arrays.sort(nums);
        permute(res, temp, nums, use);
        return res;
    }
    public void permute(List> res, List temp, int[] nums, boolean[] use){
        if(temp.size() == nums.length){
            res.add(new ArrayList<>(temp));
        }
        for(int i=0; i

 

你可能感兴趣的:(java,leetcode刷题)