package main
import (
"fmt"
"reflect"
"sort"
)
var c [][]int
//所有无重复子串
func main() {
a := []int{2, 1, 2, 2}
sort.Ints(a)
b := []int{}
son(0, a, b)
fmt.Println(c)
}
func son(num int, a, b []int) {
if num < len(a) {
b = append(b, a[num])
d := make([]int, len(b))
copy(d, b)
//对比
insert := false
for i := 0; i < len(c); i++ {
if reflect.DeepEqual(c[i], d) {
insert = true
break
}
}
if insert == false {
c = append(c, d)
}
son(num+1, a, b)
b = b[:len(b)-1]
son(num+1, a, b)
} else {
return
}
}
输出:
[[1] [1 2] [1 2 2] [1 2 2 2] [2] [2 2] [2 2 2]]