class Solution {
public:
bool backspaceCompare(string s, string t) {
int lens=s.size();
int lent=t.size();
int slow=0;
int clear=0;
int fast=0;
while(s[clear]=='#'){
fast++;
clear++;
}
for(;fast<lens;fast++){
if(s[fast]!='#'){
s[slow]=s[fast];
slow++;
}else{
if(slow>0) slow--;
}
}
s=s.substr(0,slow);
slow=0;
clear=0;
fast=0;
while(t[clear]=='#'){
fast++;
clear++;
}
for(;fast<lent;fast++){
if(t[fast]!='#'){
t[slow]=t[fast];
slow++;
}else{
if(slow>0) slow--;
}
}
t=t.substr(0,slow);
if(s==t){
return true;
}
return false;
}
};
注意退格次数不越界