MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / hasPathSum

Method hasPathSum

src/com/blankj/easy/_0112/Solution.java:15–19  ·  view source on GitHub ↗
(TreeNode root, int sum)

Source from the content-addressed store, hash-verified

13 */
14public class Solution {
15 public boolean hasPathSum(TreeNode root, int sum) {
16 if (root == null) return false;
17 if (root.left == null && root.right == null) return sum == root.val;
18 return hasPathSum(root.left, sum - root.val) || hasPathSum(root.right, sum - root.val);
19 }
20
21 public static void main(String[] args) {
22 Solution solution = new Solution();

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected