#1080
Insufficient Nodes in Root to Leaf Paths
specialist · 860 · lc medium +31 · verified · 54.9% accepted · 751 likes · top 48%
Description
Given the root of a binary tree and an integer limit, remove every node for which every root-to-leaf path through that node has a sum strictly less than limit. Return the root of the pruned tree.
A leaf is a node with no children.
Example 1:
Input: root = [1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14], limit = 1
Output: [1,2,3,4,null,null,7,8,9,null,14]
Example 2:
Input: root = [5,4,8,11,null,17,4,7,1,null,null,5,3], limit = 22
Output: [5,4,8,11,null,17,4,7,null,null,null,5]
Example 3:
Input: root = [1,2,-3,-5,null,4,null], limit = -1
Output: [1,null,-3,4]
Code
1
2
3
4
5
6
7
8
9