. [Swift] LeetCode1080 root to leaf nodes on the path insufficient | Insufficient Nodes in Root to Leaf Paths

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤ micro-channel public number: Shan Wing Chi ( shanqingyongzhi)
➤ blog Park address: San-ching Wing Chi ( https://www.cnblogs.com/strengthen/ )
➤GitHub address: https://www.cnblogs.com/strengthen/p/10993155.html 
➤ original address: https://www.cnblogs.com/strengthen/p/10470993.html 
➤ If the link is not the blog Chi Wing Shan Park address, it may be crawling author of the article.
➤ text has been modified update! Click strongly recommended that the original address read! Support authors! Support the original!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

Given the root of a binary tree, consider all root to leaf paths: paths from the root to any leaf.  (A leaf is a node with no children.)

node is insufficient if every such root to leaf path intersecting this node has sum strictly less than limit.

Delete all insufficient nodes simultaneously, and return the root of the resulting binary tree.

 

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] 

Note:

  1. The given tree will have between 1 and 5000 nodes.
  2. -10^5 <= node.val <= 10^5
  3. -10^9 <= limit <= 10^9

Given binary tree roots  root, taking into account all from the root to leaf path: the path from the root to any leaf. (Leaf node is not the child node.)

If the node to pay  node the sum of each of the root to the leaves path strictly less than the limit  limit, then the node is less than the node.

At the same time remove all deficiencies node, and returns the root of the generated binary tree. 

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 = [5, -6, -6], limit = 0 
Output: [] 

prompt:

  1. Tree has given  1 to the  5000 nodes
  2. -10^5 <= node.val <= 10^5
  3. -10^9 <= limit <= 10^9
 

Guess you like

Origin www.cnblogs.com/strengthen/p/10993155.html