input: Write a function to generate all possible permutations of a list of numbers.
  assert permute([1, 2, 3]) == [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
  assert permute([0, 1]) == [[0, 1], [1, 0]]
  assert permute([1]) == [[1]]
output: def permute(nums):
      def backtrack(start, end):
          if start == end:
              result.append(nums[:])
          for i in range(start, end):
              nums[start], nums[i] = nums[i], nums[start]
              backtrack(start + 1, end)
              nums[start], nums[i] = nums[i], nums[start]
      
      result = []
      backtrack(0, len(nums))
      return result