46. Permutations
DFS practice.
Algorithm1:
- use a stack to store current set, if len(stack) == len(nums), append stack to res
- choose a number from nums, append it to stack and mark it as used. DFS to the next level.
Algorithms2:
- use recursion to build all the possible set simultaneously.
Given a collection of distinct integers, return all possible permutations.
Example:
1 | Input: [1,2,3] |
Soulution:
1 | # standard dfs |
1 | # use recursion to build all the possible set simultaneously. |