initialize count for half nodes
count = 0 NEW_LINE while ( len ( queue ) > 0 ) : NEW_LINE INDENT node = queue . pop ( 0 ) NEW_LINE if node . left is not None and node . right is None or node . left is None and node . right is not None : NEW_LINE INDENT count = count + 1 NEW_LINE DEDENT DEDENT