10. Remove all duplicates from a given string
My Approach.
Time and Auxiliary Space Complexity
Code (C++)
class Solution {
public:
string removeDuplicates(string str) {
unordered_set<char> st;
string out;
for(auto i : str){
if(st.find(i) == st.end()){
out += i;
st.insert(i);
}
}
return out;
}
};Contribution and Support
Last updated