package main
import (
"fmt"
)
func helper(bt []byte, start int, strs *[]string) {
if start == len(bt) {
*strs = append(*strs, string(bt))
} else {
for i := start; i <= len(bt)-1; i++ {
if i != start {
tmp := bt[start]
bt[start] = bt[i]
bt[i] = tmp
}
helper(bt, start+1, strs)
if i != start {
tmp := bt[start]
bt[start] = bt[i]
bt[i] = tmp
}
}
}
}
func getAbc(s string) []string {
strs := make([]string, 0)
helper([]byte(s), 0, &strs)
return strs
}
func main() {
fmt.Println(getAbc("abcd"))
}
程序输出如下,
有疑问加站长微信联系(非本文作者)