1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| class Solution { public: bool isValid(string s) { unordered_map<char, char> mp = { { '{','}' }, { '(',')' }, { '[',']' } }; int i = 0; while(i < s.size()) { if(mp[s[i]] == s[i+1] && s[i+1] !='\0') { s.erase(i,2); i = -1; } i++; } return !s.size(); } };
|