- 题目描述
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.
每一种可能情况下有有多种可能,要求列出所有可能情况或者找最优的情况,递归是最简单的。这里的n中可能情况,每种可能下又有m中,就像一棵树一样,十分类似走迷宫的情况*(4中可能)。有的时候还不知道树的层数,这种就必须递归了。
class Solution {
public:
vector<string> letterCombinations(string digits) {
vector<string> codes = { "","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz" };
vector<string> ret;
if (digits.empty())
return ret;