Home > other >  python
python

Time:10-28

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?

CodePudding user response:

reference 1st floor harry_c 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
mean returns True when the expression was established. Not stand when it returns False