If one of the stacks is empty means other stack has extra leaves so return false
if ( len ( s1 ) == 0 or len ( s2 ) == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT temp1 = s1 . pop ( - 1 ) NEW_LINE while ( temp1 != None and not temp1 . isLeaf ( ) ) : NEW_LINE