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 | 461 Views, 26200 Search Bots | 73 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 461 Views, 26200 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 | 461 Views, 26200 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 Problem] Longest Increasing Subsequence
- Non-decreasing Array with Single Modification
- Invert a Binary Tree
- Daily Interview Problem: Min Stack
- Daily Interview Question: Find Cycles in a Graph
- Daily Interview Question: Longest Sequence with Two Unique Numbers
- Daily Interview Question: Word Search
- [Daily Problem] Longest Palindromic Substring
- Number of Ways to Climb Stairs
- CPU Utilization
©2006~2024 SteakOverCooked - 0.00791 Seconds(s) - 2320.077 KB/s - 149 Online Memory: 492.19 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 !