/**
  * 
  * @param s string字符串 
  * @return int整型
*/
func longestValidParentheses( s string ) int {
    maxAns := 0
    stack := []int{-1}
    for i := 0; i < len(s); i++ {
        if s[i] == '(' {
            stack = append(stack, i)
        }else {
            stack = stack[:len(stack)-1]
            if len(stack) == 0 {
                stack = append(stack, i)
            }else {
                maxAns = max(maxAns, i-stack[len(stack)-1])
            } 
        }
    }
    return maxAns
}
func max(a, b int) int {
    if a < b {
        return b
    }
    return a
}