2021年04月10日 周六 天气晴 【不悲叹过去,不荒废现在,不惧怕未来】
1. 题目简介
2. 题解
2.1 dp(掌握)
dp是这道题的标准解法,建议掌握。
dp思路:
class Solution {
public:
int longestValidParentheses(string s) {
const int n = s.size();
vector<int> dp(n,0);
int res = 0;
for(int i=1;i<n;++i){
// 判断当前括号是否是右括号
if(s[i]==')'){
// 前一个括号是左括号,这种情况比较简单
if(s[i-1]=='(') dp[i] = (i-2>=