LeetCode 46. Permutations(同47,只是不包含重复数字)

Given a collection of distinct numbers, return all possible permutations.

For example,
[1,2,3] have the following permutations:

[
  [1,2,3],
  [1,3,2],
  [2,1,3],
  [2,3,1],
  [3,1,2],
  [3,2,1]
]

public class Solution {
    public List> permute(int[] nums) {
        if(nums==null||nums.length==0) 
        	return null;
        int len = nums.length;
        int[] isUsed = new int[len];
        List> result = new ArrayList>();
        List store = new ArrayList();
        dfs(result,isUsed,store,nums);
        return result;
    }
    
    public void dfs(List> result, int[] isUsed, List store, int[] nums) {
    	if(store.size()==nums.length){
    		result.add(new ArrayList<>(store));
    		return;
    	}
    	for(int i=0;i


你可能感兴趣的:(LeetCode)