-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17.cpp
34 lines (32 loc) · 848 Bytes
/
17.cpp
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
//
// 17.cpp
// leetcode
//
// Created by R Z on 2018/1/31.
// Copyright © 2018年 R Z. All rights reserved.
//
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
class Solution {
public:
vector<string> letterCombinations(string digits) {
vector<string> res;
int len = digits.size();
if(!len) return res;
res.push_back("");
string charMap[10] = {"0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
for(int i=0; i<len; i++){
vector<string> tmp;
string chars=charMap[digits[i]-'0'];
for(int c=0; c<chars.length(); c++){
for(int j=0; j<res.size(); j++){
tmp.push_back(res[j]+chars[c]);
}
}
res=tmp;
}
return res;
}
};