Skip to content

Commit

Permalink
Create 2696. Minimum String Length After Removing Substrings (#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Oct 7, 2024
2 parents 3032092 + 4b35b3c commit c96b900
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions 2696. Minimum String Length After Removing Substrings
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Solution {
public:
int minLength(string s) {
int i = 0;
int flag = 0;
while (true) {
i = 0;
flag = 0;
while (i < s.size() - 1) {
if (s[i] == 'A' && s[i + 1] == 'B') {
s.erase(i, 2);
flag = 1;
} else if (s[i] == 'C' && s[i + 1] == 'D') {
s.erase(i, 2);
flag = 1;
}
if (s.size() < 2)
return s.size();
i++;
}
if (flag == 0)
break;
}
return s.size();
}
};

0 comments on commit c96b900

Please sign in to comment.