30 Days of Code [Day 14]
QUESTION : 844. Backspace String Compare
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define fo(i,s,n) for(int i=s;i<n;++i)
#define of(i,s,n) for(int i=s-1;i>=n;--i)
#define fv(V) for( auto &it : V )
class Solution {
public:
bool backspaceCompare(string s, string t) {
int n = s.size();
int m = t.size();
int c = 0;
of(i, n, 0){
if(s[i] == '#'){
c++;
s.erase(s.begin()+i);
}
else{
if(c > 0){
s.erase(s.begin()+i);
c--;
}
}
}
c = 0;
of(i, m, 0){
if(t[i] == '#'){
c++;
t.erase(t.begin()+i);
}
else{
if(c > 0){
t.erase(t.begin()+i);
c--;
}
}
}
return s==t;
}
};