17 電話號碼的字母組合

2022-09-12 23:09:24 字數 508 閱讀 5903

題目:給定乙個僅包含數字2-9的字串,返回所有它能表示的字母組合。給出數字到字母的對映如下(與**按鍵相同)。注意 1 不對應任何字母
1

//方法一:簡單遞迴

2 string dict = ;

3public listletterconbinations(string digits)

7 listresult = new arraylist<>();

8 fun(result, "", digits);

9return

result;10}

11public

void fun(listresult, string cur, string digits)

16int index = digits.charat(cur.length()) - '2';

17for(int i = 0; i)

20 }

17 電話號碼的字母組合

給定乙個數字字串,返回數字所有可能表示的字母組合。下面給出數字到字母的對映 和 號碼一樣 輸入 數字字串 23 輸出 ad ae af bd be bf cd ce cf 思路1 採用迭代的方法。class solution if digits.empty return vector vectorr...

17 電話號碼的字母組合

1.遞迴 class solution object deflettercombinations self,digits type digits str rtype list str 建立字母對應的字元列表的字典 dic 儲存結果的陣列 ret str iflen digits 0 return 遞...

17 電話號碼的字母組合

給定乙個僅包含數字2 9的字串,返回所有它能表示的字母組合。給出數字到字母的對映如下 與 按鍵相同 注意 1 不對應任何字母。圖中顯示 2 abc 3 def 4 ghi 5 jkl 6 mno 7 pqrs 8 tuv 9 wxyz 輸入 23 輸出 ad ae af bd be bf cd ce...