Solution of Letter Combinations of a Phone Number
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.
A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
ex1:
Input:
digits = "23"
Output:
["ad","ae","af","bd","be","bf","cd","ce","cf"]
ex2:
Input:
digits = "2"
Output:
["a","b","c"]
想法
- 設定一個 phone 字典對應數字與字母的關係
- 設立一個函數 run 進行字母的遍歷,加入字母可能的配對