Algorithm
Leetcode 784. Letter Case Permutation
수밈
2024. 8. 21. 16:47
## 문제 이해
문자열이 주어지면, 영문자의 경우 소문자, 대문자로 변형하여 반환하고 숫자는 그대로 반환한다고 가정했을 때 나올 수 있는 경우의 수.
## 생각해 본 방법
너무나 백트래킹 문제여서 DFS가 떠올랐다.
## Try 1. 성공
class Solution:
def letterCasePermutation(self, s: str) -> List[str]:
result = []
def DFS(L, S):
if len(s) == L:
result.append(S)
return
else:
DFS(L+1, S+s[L].lower())
if not s[L].isdigit():
DFS(L+1, S+s[L].upper())
DFS(0, '')
return result
문제 풀 때 좀 다른방법이 없는지 고민하고 풀어봐야겠다