Skip to content

Latest commit

 

History

History
23 lines (22 loc) · 652 Bytes

20.md

File metadata and controls

23 lines (22 loc) · 652 Bytes

20. Valid Parentheses

题目链接

class Solution(object):
    def isValid(self, s):
        """
        :type s: str
        :rtype: bool
        """
        kv_dict = {'{': '}', '(': ')', '[': ']'}
        data_list = []
        for i in range(len(s)):
            c = s[i]
            if c in kv_dict.keys():
                data_list.append(c)
            elif c in kv_dict.values():
                if len(data_list) == 0 or c != kv_dict[data_list.pop()]:
                    return False
        if(len(data_list) > 0):
            return False
        return True