Skip to content

Commit

Permalink
Update solution.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 1, 2024
1 parent c9dba87 commit be39032
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions kyu_7/valid_parentheses/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ def valid_parentheses(paren_str: str) -> bool:
return False

# convert string into list
paren_str = list(char for char in paren_str)
paren_str_list: list = list(paren_str)

while paren_str:
while paren_str_list:
# Fail if starts from closing bracket
if paren_str[0] == ')':
if paren_str_list[0] == ')':
return False
# Find matching pair and remove them from the string
for i in range(1, len(paren_str)):
if paren_str[i] == ')':
for i in range(1, len(paren_str_list)):
if paren_str_list[i] == ')':
# delete a matching pair
del paren_str[i]
del paren_str[0]
del paren_str_list[i]
del paren_str_list[0]
# start all over again
break

Expand Down

0 comments on commit be39032

Please sign in to comment.