Leetcode : Longest Valid Parameter

Question:https://leetcode.com/problems/longest-valid-parentheses/

Solution:

class Solution:
    def longestValidParentheses(self, s: str) -> int:
        len_string = len(s)
        count = 0
        start_bracket = 0 ## (
        for index in range(0,len_string):
            if index==0:
                if s[index]=="(":
                    start_bracket +=1
                else:
                    continue
           
            elif s[index] == "(":
                if s[index-1] == "(":
                    start_bracket+=1
                else:
                    start_bracket =1
                   
            elif s[index]==")" and start_bracket > 0:
                count+=1
                start_bracket-=1
            else:
                continue
        return count*2
Notes:
Didn't understand the problem in the rightful manner, as things were not clear.


            


Comments