Skip to content

Commit 0730190

Browse files
authored
Create 5084-insufficient-nodes-in-root-to-leaf-paths.js
1 parent 9b29cd4 commit 0730190

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* function TreeNode(val) {
4+
* this.val = val;
5+
* this.left = this.right = null;
6+
* }
7+
*/
8+
/**
9+
* @param {TreeNode} root
10+
* @param {number} limit
11+
* @return {TreeNode}
12+
*/
13+
const sufficientSubset = function(root, limit) {
14+
if (root.left == root.right)
15+
return root.val < limit ? null : root;
16+
if (root.left != null)
17+
root.left = sufficientSubset(root.left, limit - root.val);
18+
if (root.right != null)
19+
root.right = sufficientSubset(root.right, limit - root.val);
20+
return root.left == root.right ? null : root;
21+
};

0 commit comments

Comments
 (0)