Given a digit string, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below.
Input:Digit string "23" Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].<Solution>
這題簡單來說,就是根據 input 的長度去排列組合
例如 input 是 "234",那 output 會是 "adg"、"adh"、"adi"、"aeg"等
從這邊可以看出,可以用DFS來做這件事
code 如下
kotlin
沒有留言:
張貼留言