File: root - text - article - 2020 - 02 - binary-tree-level-with-minimum-sum.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 484 Views, 24541 Search Bots | 111 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 484 Views, 24541 Search Bots | 111 Words
| Browse | Archive
Hi, here's your problem today. This problem was recently asked by Twitter:
You are given the root of a binary tree. Find the level for the binary tree with the minimum sum, and return that value.
For instance, in the example below, the sums of the trees are 10, 2 + 8 = 10, and 4 + 1 + 2 = 7. So, the answer here should be 7.
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 484 Views, 24541 Search Bots | 111 Words You are given the root of a binary tree. Find the level for the binary tree with the minimum sum, and return that value.
For instance, in the example below, the sums of the trees are 10, 2 + 8 = 10, and 4 + 1 + 2 = 7. So, the answer here should be 7.
class Node:
def __init__(self, value, left=None, right=None):
self.val = value
self.left = left
self.right = right
def minimum_level_sum(root):
# Fill this in.
# 10
# / \
# 2 8
# / \ \
# 4 1 2
node = Node(10)
node.left = Node(2)
node.right = Node(8)
node.left.left = Node(4)
node.left.right = Node(1)
node.right.right = Node(2)
print minimum_level_sum(node)
Related Articles
- [Daily Problem] Move Zeros
- Sorting a list with 3 unique numbers
- Skip the readings, focus on problems. And use all the hints!
- Daily Interview Problem: Get all Values at a Certain Height in a Binary Tree
- 56 Bytes
- First and Last Indices of an Element in a Sorted Array
- Daily Interview Problem: Min Range Needed to Sort
- Daily Interview Question: Edit Distance
- Spreadsheet Column Title
- PHP Unit Tests on VPS Server
©2006~2024 SteakOverCooked - 0.00694 Seconds(s) - 2872.375 KB/s - 32 Online Memory: 492.53 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 !