diff --git a/C++/Stack/Remove Duplicate Letters cpp b/C++/Stack/Remove Duplicate Letters cpp new file mode 100644 index 0000000..ff90310 --- /dev/null +++ b/C++/Stack/Remove Duplicate Letters cpp @@ -0,0 +1,27 @@ + +string solve(string s){ +string res; +stack stk; +set present; +maplast; +for(int i=0;is[i] && last[stk.top()]>i){ + present.erase(stk.top()); + stk.pop(); + } + stk.push(s[i]); + present.insert(s[i]); +} +while(!stk.empty()){ + res+=stk.top(); + stk.pop(); +} +reverse(res.begin(),res.end()); +return res; +}