func _permutation(arr []int) [][]int{
var results = make([][]int,0)
var used = make([]int, len(arr))
helper(&results,arr,make([]int,0), used)
return results
}
func helper(results *[][]int ,arr, tmparr, used []int) *[][]int {
if len(tmparr) == len(arr) {
*results = append(*results, tmparr)
} else {
for i:=0;i<len(arr);i++ {
if used[i]==0 {
tmparr=append(tmparr,arr[i])
used[i]=1
back(results, arr, tmparr, used)
tmparr = tmparr[0:len(tmparr)-1]
used[i]=0
}
}
}
return results
}
有疑问加站长微信联系(非本文作者)