Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions valid-parentheses/chordpli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution:
def isValid(self, s: str) -> bool:
if not s or len(s) % 2 == 1:
return False

open_symbols = ['(', '[', '{']
open_box = []

for char in list(s):
if char in open_symbols:
open_box.append(char)
elif char not in open_symbols:
if not open_box:
return False
open_symbol = open_box.pop()
if open_symbol == '(' and char == ')':
continue
elif open_symbol == '[' and char == ']':
continue
elif open_symbol == '{' and char == '}':
continue
else:
return False

return len(open_box) == 0