To the Top
File:  root - text - article - 2019 - 11 - deepest-node-in-a-binary-tree.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 236 Views, 18202 Search Bots | 106 Words

Subscribe to Feed Burner | Browse | Archive
Hi, here's your problem today. This problem was recently asked by Google:

You are given the root of a binary tree. Return the deepest node (the furthest node from the root).

Example:


a
/ \
b c
/
d


The deepest node in this tree is d at depth 3.

Here's a starting point:


class Node(object):
def __init__(self, val):
self.val = val
self.left = None
self.right = None

def __repr__(self):
# string representation
return self.val


def deepest(node):
# Fill this in.

root = Node('a')
root.left = Node('b')
root.left.left = Node('d')
root.right = Node('c')

print deepest(root)
# (d, 3)
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 236 Views, 18202 Search Bots | 106 Words Subscribe to Feed Burner

Related Articles

  1. [Daily Problem] Validate Balanced Parentheses
  2. Algorithm Interview: Maximum Path Sum in Binary Tree
  3. [Daily Problem] Angles of a Clock
  4. Algorithm Interview Question: Max and Min with Limited Comparisons
  5. Reverse a Directed Graph
  6. Print a tree level-by-level, with line-breaks
  7. [Daily Problem] Add two numbers as a linked list
  8. Daily Interview Problem: Group Words that are Anagrams
  9. Skip the readings, focus on problems. And use all the hints!
  10. Longest Substring Without Repeating Characters

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