1208. Maximum Nesting Depth of Two Valid Parentheses Strings
My accepted Python solution to LeetCode problem 1208, Maximum Nesting Depth of Two Valid Parentheses Strings, running in 3ms.
- Difficulty: Medium
- Python
- Runtime 3ms
- 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 3ms, memory 17.4MB, accepted 2026-01-02.
class Solution:
def maxDepthAfterSplit(self, seq: str) -> List[int]:
# Assign parentheses at odd depth to A, even depth to B
result = []
depth = 0
for c in seq:
if c == '(':
depth += 1
result.append(depth % 2)
else:
result.append(depth % 2)
depth -= 1
return result