Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- string removeDuplicates(string S) {
- stack<char>st;
- for(auto u:S)
- {
- st.push(u);
- if(st.size()>=2)
- {
- int a,b;
- a=st.top();
- st.pop();
- b=st.top();
- st.pop();
- if(a!=b)
- {
- st.push(b);
- st.push(a);
- }
- }
- }
- string s1;
- while(!st.empty())
- {
- char c;
- c=st.top();
- s1+=c;
- st.pop();
- }
- reverse(s1.begin(),s1.end());
- return s1;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement