I. Description
II. Code
class Solution:
def letterCombinations(self, digits: str) -> List[str]:
dict = {'2': 'abc', '3': 'def', '4': 'ghi', '5': 'jkl', '6': 'mno', '7': 'pqrs', '8': 'tuv', '9': 'wxyz'}
result = []
for digit in digits:
if not result:
result = [i for i in dict[digit]]
else:
temp = result.copy()
result = []
for i in temp:
for j in dict[digit]:
result.append(i + j)
return result
Dictionary에 미리 작성해놓고 추출해가며 결과를 만들어가야 시간적으로 효율적이다.
'Coding Test > Hash Table' 카테고리의 다른 글
[LeetCode] 36. Valid Sudoku (0) | 2025.01.25 |
---|---|
[LeetCode] 12. Integer to Roman (0) | 2025.01.25 |
[LeetCode] 1930. Unique Length-3 Palindromic Subsequences (0) | 2025.01.25 |
[LeetCode] 1943. Describe the Painting (0) | 2025.01.23 |
[LeetCode] 1942. The Number of the Smallest Unoccupied Chair (0) | 2025.01.22 |