Problem :

https://leetcode.com/problems/letter-case-permutation/


My Solution :

class Solution:
def letterCasePermutation(self, S):
def dfs(path):
if len(path) == len(S):
ans.append(path)
return
c = S[len(path)]
if c.isupper():
dfs(path + c.lower())
dfs(path + c)

S = S.upper()
ans = []
dfs('')
return ans


My Solution 2 :

class Solution:
def letterCasePermutation(self, S):
S = S.upper()
ans = ['']
for c in S:
tmp = []
for prefix in ans:
if c.isupper():
tmp.append(prefix + c.lower())
tmp.append(prefix + c)
ans = tmp
return ans