Skip to content

Commit 60caa79

Browse files
authored
Create 1717. Maximum Score From Removing Substrings (#527)
2 parents 332c32f + 2c779f1 commit 60caa79

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class Solution {
2+
3+
public:
4+
int maximumGain(string s, int x, int y) {
5+
int points=0;;
6+
7+
auto removePairs = [&](char first, char second, int point){
8+
string newString;
9+
int tempPoints=0;
10+
for(char ch : s){
11+
if(!newString.empty() && newString.back()==first && ch==second){
12+
tempPoints+=point;
13+
newString.pop_back();
14+
}else{
15+
newString.push_back(ch);
16+
}
17+
}
18+
s=newString;
19+
return tempPoints;
20+
};
21+
if(x>y){
22+
points+=removePairs('a','b',x);
23+
points+=removePairs('b','a',y);
24+
}else{
25+
points+=removePairs('b','a',y);
26+
points+=removePairs('a','b',x);
27+
}
28+
return points;
29+
}
30+
};

0 commit comments

Comments
 (0)