daily log 01.25.21

less than 1 minute read

TEST CASES:

”(()” expects 2 “)()())” expects 4 “()(()” expects 2

class Solution(object):
    def longestValidParentheses(self, s):
        """
        :type s: str
        :rtype: int
        """
        
        left_stack = []
        counter = 0
        max_counter = 0
        for i in s:
            if i ==")" and len(left_stack) == 0:
                pass
            
            if i == "(":
                left_stack.append(i)
                
            
            if i == ")":
                try:
                    left_stack.pop()
                    counter += 2
                except:
                    pass
                
            
        return counter