博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
leetcode32 Longest Valid Parentheses
阅读量:4221 次
发布时间:2019-05-26

本文共 774 字,大约阅读时间需要 2 分钟。

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.

Subscribe to see which companies asked this question

python

class Solution(object):    def longestValidParentheses(self,s):        stack=[(-1,')')]        maxLen = 0        for i in range(len(s)):            if s[i]==')' and stack[-1][1]=='(':                stack.pop()                maxLen = max(maxLen,i-stack[-1][0])            else:                stack.append((i,s[i]))        return maxLenCC=Solution()s="()"print CC.longestValidParentheses(s)

转载地址:http://kwqmi.baihongyu.com/

你可能感兴趣的文章
Secure CRT 自动记录日志 配置 小记
查看>>
RMAN RAC 到 单实例 duplicate 自动分配通道 触发 ORA-19505 错误
查看>>
mysql 随机分页的优化
查看>>
DB2快速创建测试库
查看>>
利用db2look查看ddl
查看>>
SD卡驱动分析--基于高通平台
查看>>
[图文] Seata AT 模式分布式事务源码分析
查看>>
pm 源码分析
查看>>
Sending the User to Another App
查看>>
kmsg_dump
查看>>
Getting a Result from an Activity
查看>>
Allowing Other Apps to Start Your Activity
查看>>
dev/mem
查看>>
pfn_valid 源码分析
查看>>
dev/kmem 和dev/mem的区别
查看>>
test-definitions/blob/master/auto-test/bigdata/bigdata.sh
查看>>
/test-definitions/blob/master/auto-test/blktrace/blktrace.sh
查看>>
test-definitions/blob/master/auto-test/blogbench/blogbench.sh
查看>>
test-definitions/blob/master/auto-test/boost/boost.sh
查看>>
Java多态性理解
查看>>