blob: c24f36ba302beeed1c1bc958872a4f019b02909f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# 1614. Maximum Nesting Depth of the Parentheses
class Solution(object):
def maxDepth(self, s):
"""
:type s: str
:rtype: int
"""
stack = []
ans = 0
for c in s:
if c == "(":
stack.append(c)
elif c == ")":
ans = max(ans, len(stack))
stack.pop()
else:
continue
return ans
if __name__ == "__main__":
obj = Solution()
print(obj.maxDepth("(1+(2*3)+((8)/4))+1"))
print(obj.maxDepth("(1)+((2))+(((3)))"))
|