one-line java solution


  • 0
    L
    class Solution {
        public boolean hasPathSum(TreeNode root, int sum) {
            return root != null && (sum == root.val && root.left == null && root.right == null || hasPathSum(root.left, sum - root.val) || hasPathSum(root.right, sum - root.val));
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.