有没有大佬帮忙看一下这道题是什么原因,导致一直是50%
https://www.nowcoder.com/questionTerminal/45fd68024a4c4e97a8d6c45fc61dc6ad
代码如下:
class Stack:
    def __init__(self):
        self.list1=[]
        self.size=0
    def put(self,x):
        self.list1.append(x)
        self.size+=1
    def pop(self):
        if len(self.list1)==0:
            return None
        else:
            self.list1.pop()
            self.size-=1
            return
class Solution:
    def longestValidParentheses(self, s):
        # write code here
        if s=="":
            return 0
        else:
            countnum=0
            s1=Stack()
            for i in s:
                if i==')' and s1.size==0:
                    continue
                elif i==')' and s1.list1[-1]=='(':
                    countnum+=2
                    s1.pop()
                elif i=='(':
                    s1.put(i)
            return countnum
全部评论

相关推荐

1 收藏 评论
分享
牛客网
牛客企业服务