class Solution {
public:
    int longestValidParentheses(string s) 
    {
        int result=0;
        s=')'+s;
        vector<int> dp(s.length(),0);
        for(int i=1;i<s.length();i++)
        {
            if(s[i]==')')
            {
                if(s[i-1-dp[i-1]]=='(') dp[i]=dp[i-1]+2;
                dp[i]+=dp[i-dp[i]];
            }
            result=max(result,dp[i]);
        }
        return result;
    }
};

相关文章:

  • 2021-05-15
  • 2021-09-19
  • 2021-09-22
  • 2021-09-25
  • 2021-11-11
猜你喜欢
  • 2022-02-28
  • 2021-07-03
  • 2021-06-09
  • 2022-01-14
相关资源
相似解决方案