Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, determine if the input string is valid.
The brackets must close in the correct order, “()” and “()[]{}” are all valid but “(]” and “([)]” are not.
解法1: Stack O(N) Space + O(N) Time
主要考察stack的用法,用一个stack存储所有的左括号,每当遇到右括号的时候就取stack中寻找是否是match的左括号。
C++
Java