Given a string containing digits from 2-9 inclusive, 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. Note that 1 does not map to any letters.
Example:
Input: "23"
Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
Note:
Although the above answer is in lexicographical order, your answer could be in any order you want.
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
我现在好像都在搬运柳婼的代码~~~~
就当是兔式刷题吧。
先刷到一定程度,再用java龟式刷题好好学习
class Solution {
public:
vector<string> letterCombinations(string digits) {
vector<string> result;
if(digits.length()==0){
return result;
}
result.push_back("");
vector<string> v ={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
for(int i=0;i<digits.length();i++){
string s= v[digits[i]-'0'];
vector<string> temp;
for(int j=0; j<s.length();j++){
for(int k=0;k<result.size();k++){
temp.push_back(result[k]+s[j]);
}
}
result=temp;
}
return result;
}
};