LeetCode p103 Binary Tree Zigzag Level Order Traversal 题解
1.题目:
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,null,null,15,7],
3
/ \
9 20
/ \
15 7
return its zigzag level order traversal as:
[
[3],
[20,9],
[15,7]
]
题意:
输入一二叉树,返回他每层元素的列表,奇数列从左到右,偶数列从右到左。
2.解题思路:
前续遍历
3.代码
1 |
|