46_ Permutations
[Medium][Backtracking]
Given a collection of distinct integers, return all possible permutations.
Example:
Solution: Backtracking
Idea:
Think this problems as a tree problem, put one integer in each layer and do a depth-first-search to get all the paths.
When we generate the tree, we do depth first.
Change the positions of integers so that we can create each permutation in place.
Last updated
Was this helpful?