File: root - text - article - 2019 - 11 - get-all-values-at-a-certain-height-in-a-binary-tree.txt.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 270 Views, 22610 Search Bots | 81 Words
| Browse | Archive
![Subscribe to Feed Burner Subscribe to Feed Burner](/images/form/rss.gif)
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 270 Views, 22610 Search Bots | 81 Words
![Subscribe to Feed Burner Subscribe to Feed Burner](/images/form/rss.gif)
Hi, here's your problem today. This problem was recently asked by Amazon:
Given a binary tree, return all values given a certain height h.
Here's a starting point:
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 270 Views, 22610 Search Bots | 81 Words Given a binary tree, return all values given a certain height h.
Here's a starting point:
class Node():
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def valuesAtHeight(root, height):
# Fill this in.
# 1
# / \
# 2 3
# / \ \
# 4 5 7
a = Node(1)
a.left = Node(2)
a.right = Node(3)
a.left.left = Node(4)
a.left.right = Node(5)
a.right.right = Node(7)
print valuesAtHeight(a, 3)
# [4, 5, 7]
![Subscribe to Feed Burner Subscribe to Feed Burner](/images/form/rss.gif)
Related Articles
- Daily Interview Problem: Validate Binary Search Tree
- Daily Interview Problem: Decode String
- Daily Interview Problem: Minimum Removals for Valid Parenthesis
- Daily Interview Puzzle: Ways to Traverse a Grid
- Daily Interview Question: Create a Simple Calculator
- [Daily Problem] Add two numbers as a linked list
- Daily Interview Question: Edit Distance
- Algorithm Interview Question: H-Index
- Reverse a Directed Graph
- [Daily Problem] Longest Increasing Subsequence
©2006~2024 SteakOverCooked - 0.01361 Seconds(s) - 3993.43 KB/s - 33 Online
Memory: 518.2 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" />
![](/images/top.jpg)
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !