Backtracking:leetcode 46 Permutation

The article explains the simplest method to implement backtracking to solve the permutation.


Given an unrepeated integer array nums ,return its permutation array with all possibilities.

Example 1:

1Input:nums = [1,2,3]
2Output:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]

Example 2:

1Input:nums = [0,1]
2Output:[[0,1],[1,0]]

Notice:

  • 1 \(\leq\) nums.length \(\leq\) 6
  • -10 \(\leq\) nums[i] \(\leq\) 10
  • All integers in nums are not equal

Translations: