快慢指针
class Solution{
public:
bool backspaceCompare(string s,string t)
{
int slow1 = 0,slow2 = 0;
int fast1 = 0,fast2 = 0;
int len1 = s.size();
int len2 =t.size();
while(fast1<len1)
{
if(s[fast1]!='#')
{
s[slow1++]=s[fast1];
}
else
{
if(slow1>0)
{
slow1--;
}
}
fast1++;
}
while(fast2<len2)
{
if(t[fast2]!='#')
{
t[slow2++] = t[fast2];
}
else
{
if(slow2>0)
{
slow2--;
}
}
fast2++;
}
return (s.substr(0,slow1) == t.substr(0,slow2));
}
};