Closest Leaf in Binary Tree


  • 0

    Click here to see the full article post


  • 0
    X

    In Python Approach#1:

       for node in queue:
           if node:
              ....
                       queue.append(nei)
    

    modifies the list queue while iterating over it. This may result in undefined behavior.


  • 0

    @xivaxy I think every implementation of Python ever will have it always work the way we want it to, but as it's technically unspecified behavior, you are right that it would be incorrect to write the code this way. I decided to change the code anyways to not use this kind of pattern.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.