Problem Solving/LeetCode
Today's Challenge
fabichoi
2022. 5. 9. 23:45
https://leetcode.com/problems/letter-combinations-of-a-phone-number
Letter Combinations of a Phone Number - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
오랜만에 해설 안 보고 풀어봄.
최근에 회사에서 코딩 스터디를 해서 그런가.. ㅋㅋㅋ 뭔가 오기가 생긴다. (사실 쉬운 문제기도 하고)
class Solution:
def letterCombinations(self, digits: str) -> List[str]:
btns = ['', '', 'abc', 'def', 'ghi', 'jkl', 'mno', 'pqrs', 'tuv', 'wxyz']
res = []
for i in range(len(digits)):
temp = []
for btn in btns[int(digits[i])]:
temp.append(btn)
if not res:
res = temp
continue
temp2 = []
for r in res:
for t in temp:
temp2.append(r + t)
res = temp2
return res
반응형