ZigZag Order traversal
Last updated
Last updated
[[3],[20,9],[15,7]]
输入:
复制返回值:
BFS using queue to traverse the tree as usual
but when appending node to queue, we append them to the second queue, the queue storing the nodes in the next level
we also append the values of current nodes to a list
when queue is empty and nodes in current level are finished, check if we need to reverse result in the current list and reverse them if necessary, then update queue with the nodes in the second queue in the next level.
给定一个二叉树,返回该二叉树的之字形层序遍历,(第一层从左向右,下一层从右向左,一直这样交替) 例如: 给定的二叉树是{3,9,20,#,#,15,7}, 该二叉树之字形层序遍历的结果是