Valid parentheses
Given A string containing just the characters,,, ‘(‘ ‘)‘ , and ‘{‘ ‘}‘ ‘[‘ ‘]‘ , determine if the input string I S valid.
The brackets must close in the correct order, and is all valid but and is not "()" "()[]{}" "(]" "([)]" .
Using stacks, each matching pair of parentheses is out of the stack. The last stack must be empty to match exactly.
classSolution { Public: BOOLIsValid (strings) {if(s = ="") return true; Stack<Char>Stk; for(inti =0; I < s.size (); i + +) { Switch(S[i]) { Case '(': Stk.push (S[i]); Break; Case ')': if(!stk.empty () && stk.top () = ='(') Stk.pop (); Else return false; Break; Case '[': Stk.push (S[i]); Break; Case ']': if(!stk.empty () && stk.top () = ='[') Stk.pop (); Else return false; Break; Case '{': Stk.push (S[i]); Break; Case '}': if(!stk.empty () && stk.top () = ='{') Stk.pop (); Else return false; Break; default: ; } } if(Stk.empty ())return true; Else return false; }};
"Leetcode" Valid parentheses