Skip to content

Commit 9b4ea38

Browse files
authored
Create maximum-nesting-depth-of-the-parentheses.py
1 parent db79e9c commit 9b4ea38

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def maxDepth(self, s):
6+
"""
7+
:type s: str
8+
:rtype: int
9+
"""
10+
result = curr = 0
11+
for c in s:
12+
if c == '(':
13+
curr += 1
14+
result = max(result, curr)
15+
elif c == ')':
16+
curr -= 1
17+
return result

0 commit comments

Comments
 (0)