我没看懂怎么用双指针,用栈吧(阿巴阿巴阿巴,傻子流口水)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| class Solution { public: bool backspaceCompare(string S, string T) { return build(S) == build(T); }
string build(string str) { string ret; for (char ch : str) { if (ch != '#') { ret.push_back(ch); } else if (!ret.empty()) { ret.pop_back(); } } return ret; } };
|