class Solution {
public:
string removeDuplicates(string s) {
stack<char> stack;
for (int i = 0; i < s.size(); i ++) {
if (stack.empty() || s[i] != stack.top()) stack.push(s[i]);
else stack.pop();
}
string res = "";
while (!stack.empty()) res += stack.top(), stack.pop();
reverse(res.begin(), res.end());
return res;
}
};
标签:1047,string,res,top,pop,stack,字符串,LeetCode,empty
From: https://www.cnblogs.com/hjy94wo/p/16629824.html