有没有大佬帮忙看一下这道题是什么原因,导致一直是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
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
全部评论
相关推荐
PE____:都说现在环境 程序员不稳定要准备好副业,佬的副业是研究明白了
点赞 评论 收藏
分享
11-19 18:40
安徽工业大学 网络安全 点赞 评论 收藏
分享