Skip to content

Commit

Permalink
Valid Parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
nirmalnishant645 committed Jul 22, 2022
1 parent bc51e07 commit d22f98c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions 0020-Valid-Parentheses.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ class Solution:
def isValid(self, s: str) -> bool:
if len(s) % 2:
return False
brackets = {'(': ')', '{': '}', '[': ']'}
parens = {'(' : ')', '{' : '}', '[' : ']'}
stack = []
for bracket in s:
if bracket in brackets.keys():
stack.append(bracket)
elif not stack or brackets[stack.pop()] != bracket:
for paren in s:
if paren in parens.keys():
stack.append(paren)
elif not stack or paren != parens[stack.pop()]:
return False
return not stack

0 comments on commit d22f98c

Please sign in to comment.