-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1717.cpp
More file actions
30 lines (29 loc) · 720 Bytes
/
1717.cpp
File metadata and controls
30 lines (29 loc) · 720 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
25
26
27
28
29
30
class Solution {
public:
int maximumGain(string s, int x, int y) {
if (y > x) {
reverse(s.begin(), s.end());
swap(x, y);
}
int res = 0;
string t;
for (auto& c : s) {
t.push_back(c);
if (t.size() >= 2 && t.substr(t.size() - 2) == "ab") {
t.pop_back();
t.pop_back();
res += x;
}
}
string w;
for (auto& c : t) {
w.push_back(c);
if (w.size() >= 2 && w.substr(w.size() - 2) == "ba") {
w.pop_back();
w.pop_back();
res += y;
}
}
return res;
}
};