class Solution { public: string removeStars(string s) { stack<char> st; for(char ch : s) { if(ch == '*') { st.pop(); } else { st.push(ch); } } string ans; while(st.size() > 0) { ans += st.top(); st.pop(); } reverse(ans.begin(), ans.end()); return ans; } };
leetcode
challenge
Here is the link for the problem:
https://leetcode.com/problems/removing-stars-from-a-string/
Top comments (0)