package com.fishercoder.solutions;

import com.fishercoder.common.classes.TreeNode;

public class _112 {
    public static class Solution1 {
        public boolean hasPathSum(TreeNode root, int sum) {
            if (root == null) {
                return false;
            }
            if (root.val == sum && root.left == null && root.right == null) {
                return true;
            }
            return hasPathSum(root.left, sum - root.val) || hasPathSum(root.right, sum - root.val);
        }
    }
}

@@ -506,11 +506,640 @@
  %7D%0A    %7D
+%0A%0A    public static class Solution2 %7B%0A        /**%0A         * My completely original solution on 9/23/2021.%0A         */%0A        public boolean hasPathSum(TreeNode root, int targetSum) %7B%0A            return dfs(root, 0, targetSum);%0A        %7D%0A%0A        private boolean dfs(TreeNode root, int sum, int targetSum) %7B%0A            if (root == null) %7B%0A                return false;%0A            %7D%0A            sum += root.val;%0A            if (root.left == null && root.right == null) %7B%0A                return sum == targetSum;%0A            %7D%0A            return dfs(root.left, sum, targetSum) %7C%7C dfs(root.right, sum, targetSum);%0A        %7D%0A    %7D
 %0A%7D%0A

refactor 112