package leetcode;

import java.util.Stack;

public class ValidParentheses {
	public static boolean isValid(String s) {
		if (s.length() < 2) {
			return false;
		}
		String left = "({[";
		String right = ")}]";
		Stack<Character> stack = new Stack<Character>();
		stack.push(s.charAt(0));
		for (int i = 1; i < s.length(); i++) {
			if (stack.isEmpty() || right.indexOf(s.charAt(i)) == -1
					|| stack.peek() != left.charAt(right.indexOf(s.charAt(i)))) {
				stack.push(s.charAt(i));
			} else {
				stack.pop();
			}
		}
		return stack.isEmpty();
	}

	public static void main(String[] args) {
		System.out.println(isValid("[])"));
	}

}

@@ -255,16 +255,77 @@
 ter%3E();%0A
+%09%09if(right.indexOf(s.charAt(0)) != -1)%7B%0A%09%09%09return false;%0A%09%09%7D%0A
 %09%09stack.

update parentheses