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, 21233 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, 21233 Search Bots | 73 Words Subscribe to Feed Burner

Related Articles

  1. Daily Interview Problem: Deepest Node in a Binary Tree
  2. Algorithm Interview: String Compression
  3. Number of Ways to Climb Stairs
  4. Two Tricks of Delphi
  5. Binary Tree Level with Minimum Sum
  6. [Daily Problem] Remove k-th Last Element From Linked List
  7. A trick for getting good at coding interviews FASTER
  8. First and Last Indices of an Element in a Sorted Array
  9. Daily Interview Problem: Contiguous Subarray with Maximum Sum
  10. Algorithm Interview Question: Symmetric k-ary Tree

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" />