Skip to content

Commit

Permalink
Update 0046.全排列.md
Browse files Browse the repository at this point in the history
  • Loading branch information
gdnlnsjd authored May 15, 2021
1 parent cdc9b27 commit 039174e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions problems/0046.全排列.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,30 @@ public:
Java:
class Solution {
List<List<Integer>> result=new ArrayList<List<Integer>>();
Deque<Integer> path=new LinkedList<Integer>();
void backtracking(int []nums,Boolean []used) {
if(path.size()==nums.length) {
result.add(new ArrayList<Integer>(path));
return;
}
for(int i=0;i<nums.length;i++) {
if(used[i]) continue;
used[i]=true;
path.addLast(nums[i]);
backtracking(nums, used);
used[i]=false;
path.pollLast();
}
}
public List<List<Integer>> permute(int[] nums) {
Boolean []used=new Boolean[nums.length];
for(int i=0;i<used.length;i++) used[i]=false;
backtracking(nums, used);
return result;
}
}
Python:
Expand Down

0 comments on commit 039174e

Please sign in to comment.