题解 | #没有重复项数字的全排列#
没有重复项数字的全排列
http://www.nowcoder.com/practice/4bcf3081067a4d028f95acee3ddcd2b1
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 } } }