Insufficient Nodes in Root to Leaf Paths LeetCode solution in Java
1class Solution {2public TreeNode helper(TreeNode root, int limit, int sumTillNow) {3if (root == null) return null;45if (root.left == null && root.right == null) return root.val + sumTillNow < limit ? null : root;67root.left = helper(root.left, limit, sumTillNow + root.val);8root.right = helper(root.right, limit, sumTillNow + root.val);910return root.left == null && root.right == null ? null : root;11}1213public TreeNode sufficientSubset(TreeNode root, int limit) {14return helper(root, limit, 0);15}16}