Example:
1
/ \
2 3
/ \ / \
4 5 6 7
findNode(root, 5) ==> 5
null
, if desired node is not found.Queue
for the traversal.
root
is null
, return null
.Queue
object that can store tree nodes.root
.Queue
becomes empty.left
and right
nodes into the Queue
.node
, if match is found, else return null
.public TreeNode findNode(TreeNode root, int val) { }
C
Java
Python