public int longestValidParentheses(String s) {
		if (s == null || s.isEmpty()) {
			return 0;
		}

		Stack<Integer> parenthese = new Stack<Integer>();
		boolean []pos = new boolean[s.length()];
		for (int i = 0; i < pos.length; i++) {
			pos[i] = false;
		}

		char[] allStr = s.toCharArray();
		for (int i = 0; i < allStr.length; i++) {
			if (allStr[i] == '(') {
				parenthese.push(i);
			} else if (allStr[i] == ')' && !parenthese.isEmpty()) {
				int cur = parenthese.pop();
				pos[i] = true;
				pos[cur] = true;
			}
		}

		int max = 0;
		int curLen = 0;
		for (int i = 0; i < pos.length; i++) {
			if (pos[i] == true) {
				curLen++;
			} else {
				curLen = 0;
			}
			max = Math.max(max, curLen);
		}
		return max;
	}