【leetcode❤python】 20. Valid Parentheses
class Solution(object):
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
left_tag=['(','{','[']
right_tag=[')','}',']']
stack_list=[]
match_dic={'(':')','{':'}','[':']'}
for i in range(len(s)):
curcheck=s[i]
if left_tag.__contains__(curcheck):
stack_list.append(curcheck)
elif right_tag.__contains__(curcheck):
if len(stack_list)!=0 and match_dic.get(stack_list[-1])==curcheck:
stack_list.pop()
else:
return False
else:return False
return True if len(stack_list)==0 else False