做不出来,看答案看懂了
class Solution {
public int longestValidParentheses(String s) {
int max = 0;
Deque<Integer> que = new LinkedList<Integer>();
que.push(-1);
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == '(') {
que.push(i);
} else {
que.pop();
if (que.isEmpty()) {
que.push(i);
} else {
max = Math.max(max, i - que.peek());
}
}
}
return max;
}
}