How to swap nodes when the return value is void in Java?


  • 0
    S

    In Java only:
    I am confused about one thing.
    It asked to swap nodes in a tree, but no new node was returned by the function.
    So whatever you do in the function, the tree won't get changed.
    You may change the value for the particular task, but that doesn't mean you swap the nodes. you just swap the values.


  • 0
    M

    Whatever changes you make to the tree will get reflected in the original tree. There's no need to return anything!


  • 0
    S

    No! Try to swap nodes. It won't lead to any change.


Log in to reply
 

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