class Solution:
def scoreOfParentheses(self, s: str) -> int:
stack=[]
i=0
for c in s:
if c=='(':
stack.append(c)
else:
score=0
while stack[-1]!='(':
score+=stack.pop()
stack.pop()
score= score*2 if score!=0 else 1
stack.append(score)
return sum(stack)
856. Score of Parentheses
最新推荐文章于 2024-10-08 10:36:00 发布