Valid Parentheses Posted on 2018-09-28 Descriptionhttps://leetcode.com/problems/valid-parentheses/description/ Solution1234567891011121314151617181920212223242526class Solution {public: bool checkPair(char& left, char& right) { return (left == '{' && right == '}') || \ (left == '[' && right == ']') || (left == '(' && right == ')'); } bool checkLeft(char& item) { return (item == '[') || (item == '{') || (item == '('); } bool isValid(string s) { if (s.size() == 0) return true; if (s.size() % 2 || !this->checkLeft(s[0])) return false; int index = 1; stack<char> st; st.push(s[0]); while(index < s.size()) { if ( this->checkLeft(s[index]) ) st.push(s[index]); else { if (!this->checkPair(st.top(), s[index]) ) return false; st.pop(); } index += 1; } return st.empty(); }};