class Solution {
public:
bool backspaceCompare(string s, string t) {
//build two stack
stack <int> ss;
stack <int> st;
//iterate string s
for(int i = 0; i < s.size(); i++){
if(s.at(i) == '#' && !ss.empty())
ss.pop();
else if(s.at(i) != '#')
ss.push(s.at(i));
}
//iterate string t
for(int i = 0; i < t.size(); i++){
if(t.at(i) == '#' && !st.empty())
st.pop();
else if(t.at(i) != '#')
st.push(t.at(i));
}
// compare two stack
if(ss == st) return true;
else return false;
}
};
:D坚持记录的第一天