To the Top
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 | 195 Views, 21135 Search Bots | 73 Words

Subscribe to Feed Burner | 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:


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
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 195 Views, 21135 Search Bots | 73 Words Subscribe to Feed Burner

Related Articles

  1. Daily Interview Problem: Maximum Profit From Stocks
  2. Daily Interview Problem: Find the k-th Largest Element in a List
  3. Algorithm Interview: No Adjacent Repeating Characters
  4. Daily Interview Puzzle: Ways to Traverse a Grid
  5. Print a tree level-by-level, with line-breaks
  6. Spreadsheet Column Title
  7. Daily Interview Problem: First Missing Positive Integer
  8. Daily Interview Problem: Contiguous Subarray with Maximum Sum
  9. Daily Interview Problem:Create a balanced binary search tree
  10. Windows Scripting

Comments (0)

    Be the first one to comment this page !


Page Edited: May 11 2024 14:36:49 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />