610. Case Flips
A sign painter has the string s made of letters and digits. For every letter in s the painter may choose to write it in upper case or in lower case; digits are always written as they are.
Return every different string the painter can produce. Each string must appear exactly once and the strings may be returned in any order. The count is 2^k where k is the number of letters in s, so aim for time proportional to that count times the length of the string.
Example 1
- Input:
- s = "k7"
- Output:
- ["k7","K7"]
- Explanation:
One letter gives two strings,
k7andK7.
Example 2
- Input:
- s = "305"
- Output:
- ["305"]
- Explanation:
There are no letters, so the only string is
305itself.
Example 3
- Input:
- s = "aB"
- Output:
- ["aB","ab","AB","Ab"]
- Explanation:
Two letters give four strings:
ab,aB,AbandAB.
Constraints
- 1 ≤
s.length≤ 8 scontains only English letters (either case) and digits.
How this problem is judged
- Answers
- The outer list may be in any order. Everything inside each item must match exactly.
Expected complexity
- Time
- O(n * 2^n)
- Space
- O(n)