题解 | 括号配对问题
括号配对问题
https://www.nowcoder.com/practice/57260c08eaa44feababd05b328b897d7
import sys
def isValid(s: str) -> bool:
stack = []
mapping = {')': '(', ']': '['}
for char in s:
if char in '([':
stack.append(char)
elif char in ')]':
if not stack or mapping[char] != stack.pop():
return False
return not stack
s = sys.stdin.readline().strip()
result = isValid(s)
print(str(result).lower())
