java 90%


  • 0

    public List<List<Integer>> permute(int[] nums){
    List<List<Integer>> result = new ArrayList<List<Integer>>();
    res(result,nums,0,nums.length-1);
    return result;
    }
    public void res(List<List<Integer>> result,int[] nums,int start,int end){
    if(start==end){
    List<Integer> a = new ArrayList<Integer>();
    for(int i=0;i<nums.length;i++){
    a.add(nums[i]);
    }
    result.add(a);
    }else {
    for(int i=start;i<=end;i++){
    swap(nums,start,i);
    res(result,nums,start+1,end);
    swap(nums,start,i);
    }
    }
    }
    public void swap(int[] nums,int a,int b){
    int temp = nums[b];
    nums[b]=nums[a];
    nums[a]=temp;
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.