33 lines
952 B
Python
33 lines
952 B
Python
# HumanEval/6
|
|
# Loki Mode Multi-Agent Solution
|
|
# Attempts: 1
|
|
# Passed: True
|
|
|
|
from typing import List
|
|
|
|
|
|
def parse_nested_parens(paren_string: str) -> List[int]:
|
|
""" Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
|
|
For each of the group, output the deepest level of nesting of parentheses.
|
|
E.g. (()()) has maximum two levels of nesting while ((())) has three.
|
|
|
|
>>> parse_nested_parens('(()()) ((())) () ((())()())')
|
|
[2, 3, 1, 3]
|
|
"""
|
|
result = []
|
|
groups = paren_string.split()
|
|
|
|
for group in groups:
|
|
if not group:
|
|
continue
|
|
max_depth = 0
|
|
current_depth = 0
|
|
for char in group:
|
|
if char == '(':
|
|
current_depth += 1
|
|
max_depth = max(max_depth, current_depth)
|
|
elif char == ')':
|
|
current_depth -= 1
|
|
result.append(max_depth)
|
|
|
|
return result |