(nums []int)
| 1 | func permuteUnique(nums []int) [][]int { |
| 2 | numLen := len(nums) |
| 3 | res := [][]int{} |
| 4 | counter := make(map[int]int) |
| 5 | |
| 6 | for _, n := range nums { |
| 7 | counter[n]++ |
| 8 | } |
| 9 | |
| 10 | var backtrack func([]int, map[int]int) |
| 11 | |
| 12 | backtrack = func(perm []int, counter map[int]int) { |
| 13 | if len(perm) == numLen { |
| 14 | res = append(res, append([]int{}, perm...)) |
| 15 | return |
| 16 | } |
| 17 | |
| 18 | for n, count := range counter { |
| 19 | if count == 0 { |
| 20 | continue |
| 21 | } |
| 22 | perm = append(perm, n) |
| 23 | counter[n]-- |
| 24 | backtrack(perm, counter) |
| 25 | perm = perm[:len(perm)-1] |
| 26 | counter[n]++ |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | backtrack([]int{}, counter) |
| 31 | |
| 32 | return res |
| 33 | } |
nothing calls this directly
no test coverage detected