-
Notifications
You must be signed in to change notification settings - Fork 983
/
solution.h
34 lines (29 loc) · 758 Bytes
/
solution.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//
// Solution.h
// Test
//
// Created by pezy on 12/27/14.
// Copyright (c) 2014 pezy. All rights reserved.
//
#ifndef Test_Solution_h
#define Test_Solution_h
#include <vector>
#include <string>
#include <array>
using std::vector; using std::string; using std::array;
class Solution {
public:
vector<string> letterCombinations(string digits) {
vector<string> ret{""};
array<string, 10> map{"0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
for (auto digit : digits) {
vector<string> tmp;
for (auto c : map[digit - '0'])
for (const auto &pre : ret)
tmp.push_back(pre + c);
ret = tmp;
}
return ret;
}
};
#endif