From 15a2c3da52079d93c93bda96241792e439a614a3 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Wed, 27 Nov 2024 18:41:11 -0800 Subject: [PATCH] Update valid_braces.py --- kyu_6/valid_braces/valid_braces.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/kyu_6/valid_braces/valid_braces.py b/kyu_6/valid_braces/valid_braces.py index 7ab88cc49b5..24812b0580a 100644 --- a/kyu_6/valid_braces/valid_braces.py +++ b/kyu_6/valid_braces/valid_braces.py @@ -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