DEV Community

Miss Pooja Anilkumar Patel
Miss Pooja Anilkumar Patel

Posted on

2390. Leetcode Solution in cpp

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;
    }
};
Enter fullscreen mode Exit fullscreen mode

leetcode

challenge

Here is the link for the problem:
https://leetcode.com/problems/removing-stars-from-a-string/

Top comments (0)