1
class Solution {
2
unordered_map<string, vector<char>> m;
3

4
public:
5
bool dfs(string bot, int i, string tem) {
6
if (bot.size() == 1) return true;
7
if (i == bot.size() - 1) {
8
string st;
9
return dfs(tem, 0, st);
10
}
11
for (auto v : m[bot.substr(i, 2)]) {
12
tem.push_back(v);
13
if (dfs(bot, i + 1, tem)) {
14
return true;
15
}
16
tem.pop_back();
17
}
18
return false;
19
}
20
bool pyramidTransition(string bottom, vector<string> &allowed) {
21
for (auto a : allowed) {
22
m[a.substr(0, 2)].push_back(a[2]);
23
}
24
string te;
25
return dfs(bottom, 0, te);
26
}
27
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0