设为首页 加入收藏

TOP

[LeetCode]Longest Valid Parentheses
2015-07-20 17:41:58 来源: 作者: 【 】 浏览:2
Tags:LeetCode Longest Valid Parentheses

Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.

For "(()", the longest valid parentheses substring is "()", which has length = 2.

Another example is ")()())", where the longest valid parentheses substring is "()()", which has length = 4.

public class Solution {
    public int longestValidParentheses(String s) {
    	if(s==null||s.length()==0){
    		return 0;
    	}
    	Stack
  
    stack = new Stack
   
    (); int lastposition = -1;// the last not match position of ")" int res = 0; for(int i =0;i
    
     



】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU - 5001 Walk 下一篇HDU 5001 Walk(鞍山网络赛E题)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·MySQL 安装及连接-腾 (2025-12-25 06:20:28)
·MySQL的下载、安装、 (2025-12-25 06:20:26)
·MySQL 中文网:探索 (2025-12-25 06:20:23)
·Shell脚本:Linux Sh (2025-12-25 05:50:11)
·VMware虚拟机安装Lin (2025-12-25 05:50:08)