5. π(π) π πππ’π‘πππ
class Solution:
def isValid(self, s: str) -> bool:
new_s = ' '
for text in s:
if new_s[-1] == '{' and text == '}':
new_s = new_s[:-1]
continue
elif new_s[-1] == '(' and text == ')':
new_s = new_s[:-1]
continue
elif new_s[-1] == '[' and text == ']':
new_s = new_s[:-1]
continue
elif new_s[-1] == '{' and (text == ')' or text == ']'):
return False
elif new_s[-1] == '(' and (text == ']' or text == '}'):
return False
elif new_s[-1] == '[' and (text == ')' or text == '}'):
return False
new_s += text
if new_s[1:] == '':
return True
else:
return False