Skip to content

Commit

Permalink
Update valid_braces.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Nov 28, 2024
1 parent 3f51eaf commit 15a2c3d
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions kyu_6/valid_braces/valid_braces.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ def valid_braces(string: str) -> bool:
index: int = 0
while index < len(string) - 1:
char = string[index]

# in the first half of the string should
# not be any closing brackets
# in the first half of the string a new pair
# should not be starting from closing brackets
if index < (len_str // 2) and char in CLOSING:
return False

# next two brackets are matching pair
# neighbor two brackets are matching pair
if BRACES[char] == string[index + 1]:
index += 2
# matching pair consist of brackets in each
# half of the string
# matching pair consist of brackets
# in each half of the string
elif BRACES[char] == string[(index + 1) * -1]:
index += 1
# no matching pair
Expand Down

0 comments on commit 15a2c3d

Please sign in to comment.