Why it works
- The part before start is fixed; swapping each of nums[start..] into position start tries every number still free there, once each, so every order is built exactly once.
- The second swap undoes the first: when a call comes back, the list is exactly as it was, so the next i swaps from the same order and no number is lost or repeated.
- When start reaches the end, every position is fixed and the list itself is one order: a copy of it is saved.
Complexity
Time O(n × n!): n! orders, each copied in n steps; the calls above the leaves add fewer than that again. Memory O(n) besides the answer: the swaps work in the list itself, and the call stack is n deep.
nextNow solve it yourself, no hints.
Solve on LeetCode ↗