|
| 1 | +<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> |
| 2 | +<!--+----------------------------------------------------------------------+--> |
| 3 | +<!--|@author Openset <[email protected]> |--> |
| 4 | +<!--|@link https://github.com/openset |--> |
| 5 | +<!--|@home https://github.com/openset/leetcode |--> |
| 6 | +<!--+----------------------------------------------------------------------+--> |
| 7 | + |
| 8 | +[< Previous](https://github.com/openset/leetcode/tree/master/problems/letter-tile-possibilities "Letter Tile Possibilities") |
| 9 | + |
| 10 | +[Next >](https://github.com/openset/leetcode/tree/master/problems/smallest-subsequence-of-distinct-characters "Smallest Subsequence of Distinct Characters") |
| 11 | + |
| 12 | +## 1080. Insufficient Nodes in Root to Leaf Paths (Medium) |
| 13 | + |
| 14 | +<p>Given the <code>root</code> of a binary tree, consider all <em>root to leaf paths</em>: paths from the root to any leaf. (A leaf is a node with no children.)</p> |
| 15 | + |
| 16 | +<p>A <code>node</code> is <em>insufficient</em> if <strong>every</strong> such root to leaf path intersecting this <code>node</code> has sum strictly less than <code>limit</code>.</p> |
| 17 | + |
| 18 | +<p>Delete all insufficient nodes simultaneously, and return the root of the resulting binary tree.</p> |
| 19 | + |
| 20 | +<p> </p> |
| 21 | + |
| 22 | +<p><strong>Example 1:</strong></p> |
| 23 | + |
| 24 | +<pre> |
| 25 | +<strong><img alt="" src="https://assets.leetcode.com/uploads/2019/06/05/insufficient-11.png" style="width: 482px; height: 200px;" /> |
| 26 | +Input: </strong>root = <span id="example-input-1-1">[1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14]</span>, limit = <span id="example-input-1-2">1</span> |
| 27 | +<strong><img alt="" src="https://assets.leetcode.com/uploads/2019/06/05/insufficient-2.png" style="width: 258px; height: 200px;" /> |
| 28 | +Output: </strong><span id="example-output-1">[1,2,3,4,null,null,7,8,9,null,14]</span> |
| 29 | +</pre> |
| 30 | + |
| 31 | +<div> |
| 32 | +<p><strong>Example 2:</strong></p> |
| 33 | + |
| 34 | +<pre> |
| 35 | +<strong><img alt="" src="https://assets.leetcode.com/uploads/2019/06/05/insufficient-3.png" style="width: 292px; height: 200px;" /> |
| 36 | +Input: </strong>root = <span id="example-input-2-1">[5,4,8,11,null,17,4,7,1,null,null,5,3]</span>, limit = <span id="example-input-2-2">22</span> |
| 37 | +<strong><img alt="" src="https://assets.leetcode.com/uploads/2019/06/05/insufficient-4.png" style="width: 264px; height: 200px;" /> |
| 38 | +Output: </strong><span id="example-output-2">[5,4,8,11,null,17,4,7,null,null,null,5]</span></pre> |
| 39 | +</div> |
| 40 | + |
| 41 | +<p> </p> |
| 42 | + |
| 43 | +<p><strong>Note:</strong></p> |
| 44 | + |
| 45 | +<ol> |
| 46 | + <li>The given tree will have between <code>1</code> and <code>5000</code> nodes.</li> |
| 47 | + <li><code>-10^5 <= node.val <= 10^5</code></li> |
| 48 | + <li><code>-10^9 <= limit <= 10^9</code></li> |
| 49 | +</ol> |
| 50 | + |
| 51 | +<div> |
| 52 | +<div> </div> |
| 53 | +</div> |
0 commit comments