Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between).(按层从左到右->从右到左遍历二叉树)
Example:
1. 递归
与上一题类似,按层遍历,每次都把同层的树节点 Node 组合成一个 List 输入到队列,并在偶数行翻转(变形之后的BFS)。
1 | # Definition for a binary tree node. |