/**
* @param {string} s
* @return {number}
*/
var longestValidParentheses = function(s) {
//一次循环完成
var n = s.length
if (n < 1) return 0
var max = 0
var stack = []
for (var i = 0; i < n; i++){
if (s.charAt(i) === ')' && stack.length > 0 && s.charAt(stack[stack.length - 1]) === '('){
stack.pop()
if(stack.length === 0) max = Math.max(max, i + 1)
else max = Math.max(max, i - stack[stack.length - 1])
}else{
stack.push(i)
}
}
return max
};
咋么会有这么聪明的人呜呜呜