All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 15, 2024
Last updated : June 15, 2024
Related Topics : String, Backtracking, Bit Manipulation
Acceptance Rate : 74.52 %
class Solution:
def letterCasePermutation(self, s: str) -> List[str]:
s = list(s)
lowercase = 'abcdefghijklmnopqrstuvwxyz'
uppwercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
matches = {lowercase[x]: uppwercase[x] for x in range(len(lowercase))}
matches.update((uppwercase[x], lowercase[x]) for x in range(len(lowercase)))
output = []
currentOutput = []
def helper() -> None :
if len(currentOutput) == len(s) :
output.append(''.join(currentOutput))
return
currentOutput.append(s[len(currentOutput)])
helper()
currentOutput.pop()
if s[len(currentOutput)].isnumeric() :
return
currentOutput.append(matches[s[len(currentOutput)]])
helper()
currentOutput.pop()
helper()
return output