Problem Description:
Given A string containing just the characters ' (', ') ', ' {', '} ', ' [' and '] ', determine if the input string is valid.
The brackets must the correct order, "()" and "() []{} ' are all valid but ' (]" and "([)]" are not.
Ideas for solving problems:
Typical use of the pressure stack to solve the problem.
Class Solution {Public:bool isValid (string s) {stack<char> charstack;
size_t i = 0;
while (I!= s.length ()) {char c = s[i];
if (c!= ') ' && C!= '} ' && C!= '] {Charstack.push (c);
else {if (charstack.size () = = 0) return false;
char pre = Charstack.top (); Switch (c) {case ') ': if (pre = = ' (') charstack.
Pop ();
else return false;
Break
Case '} ': if (pre = = ' {') charstack.pop ();
else return false;
Break
Case '] ': if (pre = = ' [') Charstack.pop (); else return false;
Break
}} ++i;
} if (charstack.size () = = 0) return true;
else return false; }
};