ArrayList
which will be returned.Example:
1
/ \
2 3
/ \ / \
4 5 6 7
Output => 4567231
root
is null
, return.Queue
and a Stack
.root
.Queue
is not empty.left
and right
nodes into the Queue
. At the same time, push
this element onto the Stack
.pop
the Stack
's elements one by one and add them to the ArrayList
.public ArrayList<Integer> levelorderRev(TreeNode root) { }
C
Java
Python