222. Permutations of a String
Given a string s, return all unique permutations of its characters in sorted order.
- The output should be a list of strings, where each string is a valid permutation of s.
- If the string contains duplicate characters, each permutation should appear only once.
- The list should be sorted lexicographically.
You must return a list of strings, where each string is a valid permutation of s.
Example 1:
Input: s = "abc"
Output: ["abc","acb","bac","bca","cab","cba"]
Explanation: All 6 permutations of 3 distinct characters.
Example 2:
Input: s = "aab"
Output: ["aab","aba","baa"]
Explanation: Only 3 unique permutations due to duplicate 'a'.
Now Your Turn!
Pick the correct output for the given inputInput: s = "aa"
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= s.length <= 8
- s consists of lowercase English letters (a to z)
- Return only unique permutations if the input string has duplicate characters