sirnay
2020-12-18 12:35:30 +08:00
func permuteUnique(nums []int) (ans int) {
sort.Ints(nums)
n := len(nums)
perm := []int{}
vis := make([]bool, n)
r := make([]int, 0)
var backtrack func(int)
backtrack = func(idx int) {
if idx == n {
tmp := make([]int, len(perm))
copy(tmp, perm)
sum := 0
for i := 0; i < len(perm); i++ {
sum += tmp[i] * int(math.Pow10(i))
}
if sum > 300000 {
ans++
r = append(r, sum)
}
return
}
for i, v := range nums {
//
if vis[i] || i > 0 && !vis[i-1] && v == nums[i-1] {
continue
}
perm = append(perm, v)
vis[i] = true
backtrack(idx + 1)
vis[i] = false
perm = perm[:len(perm)-1]
}
}
backtrack(0)
return
}