Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

valid paranthesis

    def isValid(self, s: str) -> bool:
        if len(s)&1!=0:
            return False
        q=deque()
        for i in s:
            if i=='(' or i=='{' or i=='[':
                q.append(i)
            elif len(q)!=0 and ((q[-1]=='(' and i==')') or (q[-1]=='[' and i==']') or (q[-1]=='{' and i=='}')):
                q.pop()
            else:
                return False
        if len(q)==0:
            return True
        return False
Source by leetcode.com #
 
PREVIOUS NEXT
Tagged: #valid #paranthesis
ADD COMMENT
Topic
Name
7+1 =