class Solution {
public:
bool backspaceCompare(string S, string T)
{
string ans, res;
for (int i = 0; i < S.length(); i++)
{
if (isalpha(S[i]))
{
res += S[i];
}
else
{
if (res.length() == 0)
{
continue;
}
else
{
res = res.substr(0, res.length() -1);
}
}
}
for (int i = 0; i < T.length(); i++)
{
if (isalpha(T[i]))
{
ans += T[i];
}
else
{
if (ans.length() == 0)
{
continue;
}
else
{
ans = ans.substr(0, ans.length() - 1);
}
}
}
if (ans == res)
return true;
else
return false;
}
};
不愧是我,一次AC