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, 27288 Search Bots | 73 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 485 Views, 27288 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, 27288 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
- Plus One
- Daily Interview Problem: Trapping Rainwater
- Daily Interview Puzzle: Ways to Traverse a Grid
- Algorithm Interview Question: Symmetric k-ary Tree
- Design Tic-Tac-Toe
- Skip the readings, focus on problems. And use all the hints!
- Find Missing Numbers in an Array
- Daily Interview Problem: Find the Number of Islands
- Daily Interview Question: Word Search
- Top K Frequent words
©2006~2024 SteakOverCooked - 0.0068 Seconds(s) - 2802.179 KB/s - 42 Online Memory: 492.5 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 !