- Binary Tree Zigzag Level Order T
- 69. Binary Tree Level Order Trav
- 107 Binary Tree Level Order Trav
- 102 Binary Tree Level Order Trav
- 107 Binary Tree Level Order Trav
- 102 Binary Tree Level Order Trav
- 【1错2对1】N-ary Tree Level Order Tr
- Leetcode - Binary Tree Level Ord
- [leetcode] 102. Binary Tree Leve
- Leetcode 102. Binary Tree Level
Description
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).
The first data is the root node, followed by the value of the left and right son nodes, and "#" indicates that there is no child node.
The number of nodes does not exceed 20.
Example
Example 1:
Input:{1,2,3}
Output:[[1],[2,3]]
Explanation:
1
/ \
2 3
it will be serialized {1,2,3}
level order traversal
Example 2:
Input:{1,#,2,3}
Output:[[1],[2],[3]]
Explanation:
1
\
2
/
3
it will be serialized {1,#,2,3}
level order traversal
Challenge
Challenge 1: Using only 1 queue to implement it.
Challenge 2: Use BFS algorithm to do it.
思路:
有两种解法, 以一是用一个队列, 二是用两个队列交换
代码:
用1个队列的
用两个队列的:
网友评论