每日刷題 電話號碼的字母組合

2021-09-10 16:00:40 字數 950 閱讀 5179

給定乙個僅包含數字 2-9 的字串,返回所有它能表示的字母組合。

給出數字到字母的對映如下(與**按鍵相同)。注意 1 不對應任何字母。

示例:

輸入:「23」

輸出:[「ad」, 「ae」, 「af」, 「bd」, 「be」, 「bf」, 「cd」, 「ce」, 「cf」].

解答:這道題有點類似於 全排列,這裡使用dfs演算法。

**:

vector result;

vector

lettercombinations

(string digits)

; string temp ="";

enumeration(0

, rec, temp)

;return result;

}void

enumeration

(int k, vector< string> record , string &temp)

for(

int i =

0; i < record[k]

.size()

; i++)if

( temp.

size()

) temp.

erase

( temp.

size()

-1);

}

執行結果:

電話號碼的字母組合

給乙個數字字串,每個數字代表乙個字母,請返回其所有可能的字母組合。下圖的手機按鍵圖,就表示了每個數字可以代表的字母。樣例給定 23 返回 ad ae af bd be bf cd ce cf 注意以上的答案是按照詞典編撰順序進行輸出的,不過,在做本題時,你也可以任意選擇你喜歡的輸出順序。class ...

電話號碼的字母組合

給定乙個僅包含數字2 9的字串,返回所有它能表示的字母組合。給出數字到字母的對映關係如下 示例 輸入 23 輸出 ad ae af bd be bf cd ce cf 注 輸出字串順序任意 我的 public class lettercombinationsofaphonenumber public...

電話號碼的字母組合

這是一道我刷題時遇到的乙個題目,很簡單,輸入數字,輸出這些數字構成的字元排列組合 由可以看出。given a string containing digits from 2 9 inclusive,return all possible letter combinations that the nu...