046.Permutations Posted on 2017-09-16 | In LeetCode Solution 1: accepted 7msDFS, similar to question 078. 12345678910111213141516171819202122class Solution { public List<List<Integer>> permute(int[] nums) { List<List<Integer>> result = new ArrayList<List<Integer>>(); List<Integer> list = new ArrayList<>(); permuteHelper(result, list, nums); return result; } public void permuteHelper(List<List<Integer>> result, List<Integer> list, int[] nums) { if (nums.length == list.size()) { result.add(new ArrayList<Integer>(list)); // use "else" or "return" after it to end the recursion } else { for (int i = 0; i < nums.length; i++) { if (!list.contains(nums[i])) { list.add(nums[i]); permuteHelper(result, list, nums); list.remove(list.size() - 1); } } } }}