File: root - text - article - 2020 - 01 - level-order-traversal-of-binary-tree.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 485 Views, 27234 Search Bots | 73 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 485 Views, 27234 Search Bots | 73 Words
| Browse | Archive
Hi, here's your problem today. This problem was recently asked by Microsoft:
Given the root of a binary tree, print its level-order traversal. For example:
The following tree should output 1, 2, 3, 4, 5.
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 485 Views, 27234 Search Bots | 73 Words Given the root of a binary tree, print its level-order traversal. For example:
1
/ \
2 3
/ \
4 5
The following tree should output 1, 2, 3, 4, 5.
class Node:
def __init__(self, val, left=None, right=None):
self.val = val
self.left = left
self.right = right
def print_level_order(root):
# Fill this in.
root = Node(1, Node(2), Node(3, Node(4), Node(5)))
print_level_order(root)
# 1 2 3 4 5
Related Articles
- Daily Interview Problem: Full Binary Tree
- Sort a Partially Sorted List
- Patterns for breaking down questions you haven
- [Daily Problem] Angles of a Clock
- Algorithm Interview: Convert Roman Numerals to Decimal
- Daily Interview Problem: Arithmetic Binary Tree
- Daily Interview Problem: Decode String
- Algorithm Interview: Make the Largest Number
- [Daily Problem] Remove Consecutive Nodes that Sum to 0
- Consecutive Ones
©2006~2024 SteakOverCooked - 0.00805 Seconds(s) - 2313.103 KB/s - 31 Online Memory: 492.39 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Comments (0)
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !