栈的基础知识介绍:http://www.nhooo.com/java/java-stack.html
必须掌握之算法
class Solution {
public boolean isValid(String s) {
char[] array = s.toCharArray();
Stack<Character> stack = new Stack<>();
for (int i = 0; i < array.length; ++i) {
if (array[i] == '(' || array[i] == '[' || array[i] == '{') {
stack.push(array[i]);
} else if (!stack.isEmpty()
&& (array[i] == ')' && stack.peek() == '('
|| array[i] == ']' && stack.peek() == '['
|| array[i] == '}' && stack.peek() == '{')) {
stack.pop();
} else {
return false;
}
}
return stack.isEmpty();
}
}