Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- string removeStars(string s) {
- stack<int> st;
- string s1="";
- for(int i=0;i<s.length();i++)
- {
- if(s[i]!='*')
- {
- st.push(s[i]);
- }
- else if(s[i]=='*' && !st.empty())
- {
- st.pop();
- }
- }
- while(!st.empty())
- {
- s1+=st.top();
- st.pop();
- }
- reverse(s1.begin(),s1.end());
- return s1;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment