栈的应用
public boolean isValid(String s) { Stack<Character> stack = new Stack<>(); for ( int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == '(' || c == '[' || c == '{') { stack.push(s.charAt(i)); } else { if (stack.empty()) { return false; } char left = stack.pop(); if (c == ')' && left == '(') { } else if (c == ']' && left == '['){ } else if (c == '}' && left == '{') { } else { return false; } } }// end for if (stack.empty()) { return true; } else { return false; } }