-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# 17. 电话号码的字母组合 | ||
|
||
## 题目描述 | ||
|
||
给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合。答案可以按 任意顺序 返回。 | ||
|
||
给出数字到字母的映射如下(与电话按键相同)。注意 1 不对应任何字母。 | ||
|
||
## 解题思路 | ||
|
||
```cpp | ||
class Solution { | ||
public: | ||
const string a[10] = { | ||
"", // 0 | ||
"", // 1 | ||
"abc", // 2 | ||
"def", // 3 | ||
"ghi", // 4 | ||
"jkl", // 5 | ||
"mno", // 6 | ||
"pqrs", // 7 | ||
"tuv", // 8 | ||
"wxyz", // 9 | ||
}; | ||
vector<string>res; | ||
string cur; | ||
string digits; | ||
void b(int start) { | ||
if(cur.size()==digits.size()){res.push_back(cur);return;} | ||
string letters=a[digits[start]-'0']; | ||
for(char c:letters){ | ||
cur.push_back(c); | ||
b(start+1); | ||
cur.pop_back(); | ||
} | ||
} | ||
vector<string> letterCombinations(string digits) {if(digits.size()==0)return vector<string>{}; | ||
this->digits=digits;b(0);return res; | ||
} | ||
}; | ||
``` | ||
## 学习感想 |
File renamed without changes.