[LeetCode][Python3] 784. Letter Case Permutation
2019. 8. 20. 00:50 |
프로그래밍/LeetCode
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
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 39. Combination Sum (0) | 2019.08.23 |
---|---|
[LeetCode][Python3] 216. Combination Sum III (0) | 2019.08.23 |
[LeetCode][Python3] 52. N-Queens II (0) | 2019.08.23 |
[LeetCode][Python3] 526. Beautiful Arrangement (0) | 2019.08.21 |
[LeetCode][Python3] 980. Unique Paths III (0) | 2019.08.20 |
[LeetCode][Python3] 47. Permutations II (0) | 2019.08.18 |
[LeetCode][Python3] 1079. Letter Tile Possibilities (0) | 2019.08.16 |
[LeetCode][Python3] 765. Couples Holding Hands (0) | 2019.08.15 |
최근에 달린 댓글 최근에 달린 댓글