Problem
Problem page: https://leetcode.com/problems/permutations-ii/
Topics: Backtracking
Difficulty: Medium
Similar problems: (M) Next Permutation, (M) Permutations, (M) Palindrome Permutation II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.
For example,
[1,1,2]have the following unique permutations:
[1,1,2],[1,2,1], and[2,1,1].
Analysis
The only difference from Permutations is that I skip duplicate elements without trying to swap them, to avoid duplicate permutations.
Code
1 | class Solution: |
Article link: https://xnerv.wang/en/leetcode-permutations-ii/
