leetcode 17 Letter Combinations of a Phone Number
Posted 王坤1993
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode 17 Letter Combinations of a Phone Number相关的知识,希望对你有一定的参考价值。
class Solution { public: vector<string> letterCombinations(string digits) { vector<string> res; if (digits.empty()) return res; string dict[] = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; res.push_back(""); for (int i = 0; i < digits.size(); ++i) { int n = res.size(); string str = dict[digits[i] - ‘2‘]; for (int j = 0; j < n; ++j) { string tmp = res.front(); res.erase(res.begin()); for (int k = 0; k < str.size(); ++k) { res.push_back(tmp + str[k]); } } } return res; } };
以上是关于leetcode 17 Letter Combinations of a Phone Number的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode算法题python解法:17. Letter Combinations of a Phone Number
Leetcode 17.——Letter Combinations of a Phone Number
LeetCode-17-Letter Combinations of a Phone Number
LeetCode17. Letter Combinations of a Phone Number