题目:
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).
For example:
Given binary tree {3,9,20,#,#,15,7}
,
3 / 9 20 / 15 7
return its zigzag level order traversal as:
[ [3], [20,9], [15,7] ]
题解:
这题同样是BFS,用一个flag记录是否需要reverse,如果需要的话就把reverse的结果存储即可。
代码如下:
Binary Tree ZigZag Level Order Traversal leetcode java,布布扣,bubuko.com
Binary Tree ZigZag Level Order Traversal leetcode java
原文:http://www.cnblogs.com/springfor/p/3891393.html