题目地址:https://leetcode-cn.com/problems/valid-parentheses/
解题思路:栈的操作
class Solution { public: bool isValid(string s) { stack<char> q; for (int i = 0; i < s.size(); i++) { if (q.empty()) q.push(s[i]); else { if ((q.top() == '('&&s[i] == ')') || (q.top() == '['&&s[i] == ']') || (q.top() == '{'&&s[i] == '}')) q.pop(); else q.push(s[i]); } } if (q.empty()) return true; else return false; } };