Def valid_parentheses (s) : stack=list () dict={' (', ') ', '(',') ', '{}' : ' '} for c in s: if c in dict. The keys () : stack. The append (dict [c]) elif c in dict. The values () : if len (stack)==0 or c!=stack. Pop () : the else: return False False return len (stack)==0 return here len (stack)==0 is what meaning, if not met before def valid_parentheses (string) : count=0 for I in string: if I=="(" : count +=1 elif I==") ": the count -=1 if the count & lt; 0: return False return count==0 and asked the final return here
CodePudding user response:
Should first understand the len (stack)==0, which is an expression when the stack is empty expression is True or False, return will return to, the calculation results
CodePudding user response:
That is to say, return True when the expression was established not stand is False?