[x] Improve - Valid Parentheses

20. Valid Parentheses | Easy

Runtime: 48 ms, faster than 38.56% of Python3 online submissions for Valid Parentheses.

class Solution:
    def isValid(self, s):
        """
        :type s: str
        :rtype: bool
        """
        if len(s) == 0:
            return True
        stack = []
        for elem in s:
            if elem == '{':
                stack += '}'
            elif elem == '[':
                stack += ']'
            elif elem == '(':
                stack += ')'
            elif len(stack) >= 1 and elem == stack[-1]:
                stack = stack[:-1]
            elif elem == '}':
                return False
            elif elem == ']':
                return False
            elif elem == ')':
                return False
            else:
                continue
                
        return True if len(stack) == 0 else False