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 | 481 Views, 22524 Search Bots | 106 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 481 Views, 22524 Search Bots | 106 Words
| 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:
The deepest node in this tree is d at depth 3.
Here's a starting point:
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 481 Views, 22524 Search Bots | 106 Words 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)
Related Articles
- Reverse a Linked List
- Daily Interview Problem: Word Ordering in a Different Alphabetical Order
- Daily Interview Problem: Merge List Of Number Into Ranges
- Daily Interview Problem: Maximum Profit From Stocks
- Algorithm Interview: Maximum Path Sum in Binary Tree
- Reverse a Directed Graph
- Daily Interview Problem: Look and Say Sequence
- Daily Interview Problem: Find the k-th Largest Element in a List
- Find Missing Numbers in an Array
- Maximum In A Stack
©2006~2024 SteakOverCooked - 0.00752 Seconds(s) - 7182.112 KB/s - 39 Online Memory: 517.52 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 !