MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / Solution

Class Solution

Python/20_ValidParentheses.py:22–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20"""
21
22class Solution:
23 def isValid(self, s: str) -> bool:
24 parentheses = {'(':')', '{':'}', '[':']'}
25 stack = []
26 for b in s: # take bracket 'b' from string 's'
27 if b in parentheses: # if bracket in parentheses
28 stack.append(parentheses[b]) # append it's opposite to stack
29 elif not stack or stack.pop() != b: # if not stack or bracket not
30 return False # equal last bracket in stack
31 return not stack # if stack still exists -> False else True

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected