leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1249.cpp (528B)
0 class Solution { 1 public: 2 string minRemoveToMakeValid(string s) { 3 stack<int> st; 4 for (auto i = 0; i < s.size(); i++) { 5 if (s[i] == '(') 6 st.push(i); 7 else if (s[i] == ')') { 8 if (!st.empty()) 9 st.pop(); 10 else 11 s[i] = '*'; 12 } 13 } 14 while (!st.empty()) 15 s[st.top()] = '*', st.pop(); 16 s.erase(remove(s.begin(), s.end(), '*'), s.end()); 17 return s; 18 } 19 };