844. Backspace String Compare
作者:
张小盒small | 来源:发表于
2019-08-04 19:42 被阅读0次class Solution {
public:
bool backspaceCompare(string S, string T) {
stack<char> first;
stack<char> second;
for (auto item : S){
if (!first.empty() && item == '#')
first.pop();
if (item != '#')
first.push(item);
}
for (auto item : T){
if (!second.empty() && item == '#')
second.pop();
if (item != '#')
second.push(item);
}
return first == second;//判断栈是否相等,此处只是用于判断其中的元素是否全部相等
}
};
本文标题:844. Backspace String Compare
本文链接:https://www.haomeiwen.com/subject/xonydctx.html
网友评论