10.19字符串含退格符
方法一:使用栈弹出
class Solution
{
public:
bool backspaceCompare(std::string s, std::string t)
{
return build(s) == build(t);
}
std::string build(std::string s)
{
std::stackstd::string ret;
for (auto ch:s)
{
if (ch != ‘#’)
{
///字符转换成字符串
std::string temp = “”;
temp[0] = ch;
ret.push(temp);
}
else if (!ret.empty())
{
ret.pop();
}
}
std::string res;
while (ret.empty())
{
//增加弹出元素
std::string popElement=ret.top();
ret.pop();
res += popElement;
}
return res;
}
};