bool backspaceCompare(string S, string T) {
stack<char> temp1;
stack<char> temp2;
for(auto x:S)
{
if(x!='#')
temp1.push(x); //在栈顶加入一个元素x
if(x=='#'&&!temp1.empty())
temp1.pop(); //在栈顶移除一个元素x
}
for(auto x:T)
{
if(x!='#')
temp2.push(x); //在栈顶加入一个元素x
if(x=='#'&&!temp2.empty())
temp2.pop(); //在栈顶移除一个元素x
}
if(temp1==temp2)
return true;
else
return false;
}
};
int main()
{
string S1="ab##";
string S2="c#d#";
cout<<Solution::backspaceCompare(S1,S2);
return 0;
}
06-24
08-07