-
Notifications
You must be signed in to change notification settings - Fork 481
/
0936.cpp
38 lines (38 loc) · 1.02 KB
/
0936.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
35
36
37
38
class Solution
{
public:
vector<int> movesToStamp(string stamp, string target)
{
int s_len = stamp.size(), t_len = target.size();
const auto check = [&](int k) {
bool res = false;
for (int i = 0; i < s_len; i++)
{
if (target[k + i] != '?')
{
if (target[k + i] != stamp[i]) return false;
res = true;
}
}
return res;
};
string done(t_len, '?');
vector<int> res;
while (target != done)
{
bool move = false;
for (int i = 0; i < t_len - s_len + 1; i++)
{
if (check(i))
{
move = true;
res.push_back(i);
fill(target.begin() + i, target.begin() + i + s_len, '?');
}
}
if (!move) return {};
}
reverse(res.begin(), res.end());
return res;
}
};