forked from lzl124631x/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths2.cpp
More file actions
24 lines (24 loc) · 699 Bytes
/
s2.cpp
File metadata and controls
24 lines (24 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// OJ: https://leetcode.com/problems/letter-combinations-of-a-phone-number/
// Author: github.com/lzl124631x
// Time: O(4^N * N)
// Space: O(4^N * N)
class Solution {
private:
vector<string> M{ "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
public:
vector<string> letterCombinations(string digits) {
if (digits.empty()) return {};
vector<string> ans{""};
for (char c : digits) {
vector<string> next;
string m = M[c - '2'];
for (string s : ans) {
for (char c : m) {
next.push_back(s + c);
}
}
ans = next;
}
return ans;
}
};