My simple 8ms C++ code
class Solution {\n    public:\n        int longestValidParentheses(string s) {\n            stack<int> stk;\n            stk.push(-1);\n            int maxL=0;\
    class Solution {\n    public:\n        int longestValidParentheses(string s) {\n            stack<int> stk;\n            stk.push(-1);\n            int maxL=0;\n            for(int i=0;i<s.size();i++)\n            {\n                int t=stk.top();\n                if(t!=-1&&s[i]==')'&&s[t]=='(')\n                {\n                    stk.pop();\n                    maxL=max(maxL,i-stk.top());\n                }\n                else\n                    stk.push(i);\n            }\n            return maxL;\n        }\n    };
[]