Skip to content

Grind 75 - Valid Parentheses

Posted on:July 21, 2023 at 02:36 PM at 1 min read

Solution for Valid Parentheses problem which is a part of Grind 75 list.

class Solution:
    def isValid(self, s: str) -> bool:

        mapping = {'(':')', '{':'}', '[':']'}
        stack = []

        for char in s:
            if char in mapping:
                stack.append(char)
                continue

            if not stack or mapping[stack.pop()] != char:
                return False

        return not stack

Comments