Given a string s, you can transform every letter individually to be lowercase or uppercase to create another string. Digits stay as they are.
Return a list of all possible strings you could create.
Function Signature
def letter_case_permutation(s: str) -> list[str]:
Rules
-
Return the strings sorted in ascending order by character code, which is Python's default string order. Digits sort before uppercase letters, and an uppercase letter sorts before its lowercase form (
'A' < 'a'
).
-
Each string appears once in the result. The original
s
is included as one of the strings.
Constraints
-
1 <= len(s) <= 12
-
s
consists of lowercase English letters, uppercase English letters, and digits.
Examples
Input: s = "a1b2"
Output: ["A1B2", "A1b2", "a1B2", "a1b2"]
Each of a and b can be lowercase or uppercase, giving 2 * 2 = 4 strings. In sorted order the uppercase choice comes first at each letter position.
Input: s = "3z4"
Output: ["3Z4", "3z4"]
Only z is a letter, so there are two strings, and "3Z4" sorts before "3z4".
Input: s = "12345"
Output: ["12345"]
There are no letters, so the only string is s itself.