Files
PS/leetcode/20.py
Gyubin Han dede0dca01 leetcode
2025-02-19 14:09:55 +09:00

22 lines
523 B
Python

class Solution:
def isValid(self, s: str) -> bool:
arr=[]
for c in s:
if c in ['(','{','[']:
arr.append(c)
continue
if c in [')','}',']']:
if len(arr)<0+1:
return False
p=arr.pop()
if not((c==')' and p=='(') or (c=='}' and p=='{') or (c==']' and p=='[')):
return False
if len(arr)>0:
return False
else:
return True