package main

/** *

  • @param num int整型一维数组
  • @return int整型二维数组 */ var res [][]int func permute( nums []int ) [][]int { // write code here res = [][]int{} path := []int{} used := make([]bool, len(nums)) backpack(nums, path, used) return res } func backpack(nums []int, path []int, used []bool) { if len(path) == len(nums) { temp := make([]int, len(path)) copy(temp, path) res = append(res, temp) return } for i := 0; i < len(nums); i++ { if !used[i] { used[i] = true path = append(path, nums[i]) backpack(nums, path, used) path = path[:len(path) - 1] used[i] = false } } }