leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1047.cpp (419B)


0 class Solution { 1 public: 2 string removeDuplicates(string s) { 3 stack<char> st; 4 for (char c : s) 5 if (st.empty() || c != st.top()) 6 st.push(c); 7 else 8 st.pop(); 9 10 string res = ""; 11 while (!st.empty()) { 12 res += st.top(); 13 st.pop(); 14 } 15 reverse(res.begin(), res.end()); 16 return res; 17 } 18 };