Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a727f80

Browse files
Create: 2390-removing-stars-from-a-string.cpp (#1)
- File(s) Modified: 2390-removing-stars-from-a-string.cpp - Language(s) Used: C++ - Submission URL: https://leetcode.com/problems/removing-stars-from-a-string/submissions/1140574034/
1 parent de257c5 commit a727f80

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
string removeStars(string s) {
4+
stack<char> stk;
5+
for(int i=0;i<s.size();i++){
6+
if(s[i]=='*'){
7+
stk.pop();
8+
}else stk.push(s[i]);
9+
}
10+
string res = "";
11+
while(!stk.empty()){
12+
res += stk.top();
13+
stk.pop();
14+
}
15+
reverse(res.begin(), res.end());
16+
return res;
17+
}
18+
};

0 commit comments

Comments
 (0)