资讯详情

二刷hot100-32.最长有效括号

📅 2026/9/25 12:34:09 | 华诺云谱 👁 阅读
二刷hot100-32.最长有效括号
有点复杂https://www.bilibili.com/video/BV1ehGjzJEiq/?spm_id_from333.337.search-card.all.clickvd_source757bb2dbaa360a4764731a4b0a025637class Solution { public int longestValidParentheses(String s) { int[] len new int[s.length()]; char[] ch s.toCharArray(); int res 0; for(int i 1;i ch.length;i){ if(ch[i] )){ if((i - 1) 0 ch[i - 1] (){ len[i] (i - 2) 0 ? len[i - 2] 2 : 2; }else if((i - 1) 0 ch[i - 1] )){ int m i - len[i - 1] - 1; if(m 0 ch[m] (){ len[i] (m - 1) 0 ? 2 len[i -1] len[m - 1] : 2 len[i - 1]; } } res Math.max(res,len[i]); } } return res; } }
📝

华诺云谱内容团队

资深建站顾问 · 行业研究员

10年+企业数字化服务经验,专注智能建站、SEO优化与品牌营销,持续输出建站技巧、行业洞察与营销干货,已帮助5000+企业实现数字化增长。

你可能需要的服务

订阅华诺云谱资讯周报

每周一封,精选建站技巧、SEO与营销干货,直达邮箱。已有 8,000+ 企业主订阅,助你少走弯路。

↑