[题目地址](https://leetcode.cn/problems/permutations-ii/description/) ```go func permuteUnique(nums []int) [][]int { slices.Sort(nums) var ans [][]int n := len(nums) onPath := make([]bool,n) path := make([]int, n) var dfs func(int) dfs = func(i int){ if i == n{ ans = append(ans, slices.Clone(path)) return } for j, on := range onPath{ if on || j > 0 && nums[j] == nums[j - 1] && !onPath[j - 1]{ continue } path[i] = nums[j] onPath[j] = true dfs(i + 1) onPath[j] = false } } dfs(0) return ans } ```