1737. Maximum Nesting Depth of the Parentheses
My accepted Python solution to LeetCode problem 1737, Maximum Nesting Depth of the Parentheses, running in 0ms.
- Difficulty: Easy
- Python
- Runtime 0ms
- Memory 17.4MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.4MB, accepted 2025-12-31.
class Solution:
def maxDepth(self, s: str) -> int:
max_depth = 0
current_depth = 0
for char in s:
if char == '(':
current_depth += 1
max_depth = max(max_depth, current_depth)
elif char == ')':
current_depth -= 1
return max_depth