Make The String Great LeetCode solution in C++

1
class Solution {
2
public:
3
string makeGood(string s) {
4
stack<char> st;
5
st.push(s[0]);
6
string ans = "";
7

8
for (int i = 1; i < s.size(); ++i) {
9
if (!st.empty() and (st.top() == s[i] + 32 or st.top() == s[i] - 32)) {
10
cout << "top :" << st.top() << endl;
11
st.pop();
12
}
13

14
else {
15
st.push(s[i]);
16
}
17
}
18

19
while (!st.empty()) {
20
// cout<<st.top()<<"";
21
ans += st.top();
22
st.pop();
23
}
24
reverse(ans.begin(), ans.end());
25

26
return ans;
27
}
28
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0