package com.fishercoder.solutions;

import com.fishercoder.common.classes.TreeNode;

/**
 * 112. Path Sum

Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.

For example:
Given the below binary tree and sum = 22,

              5
             / \
            4   8
           /   / \
          11  13  4
         /  \      \
        7    2      1

 return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22.*/
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);
    }
  }
}

@@ -82,450 +82,8 @@
 e;%0A%0A
-/**%0A * 112. Path Sum%0A%0AGiven a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.%0A%0AFor example:%0AGiven the below binary tree and sum = 22,%0A%0A              5%0A             / %5C%0A            4   8%0A           /   / %5C%0A          11  13  4%0A         /  %5C      %5C%0A        7    2      1%0A%0A return true, as there exist a root-to-leaf path 5-%3E4-%3E11-%3E2 which sum is 22.*/%0A
 publ
@@ -98,16 +98,18 @@
  _112 %7B%0A
+  
   public
@@ -134,24 +134,28 @@
 tion1 %7B%0A    
+  
+  
 public boole
@@ -190,24 +190,30 @@
  int sum) %7B%0A
+      
       if (ro
@@ -218,32 +218,40 @@
 root == null) %7B%0A
+        
         return f
@@ -256,16 +256,22 @@
  false;%0A
+      
       %7D%0A
@@ -272,24 +272,30 @@
     %7D%0A      
+ 
+     
 if (root.val
@@ -340,32 +340,40 @@
 ight == null) %7B%0A
+        
         return t
@@ -379,26 +379,38 @@
 true;%0A      
+   
-%7D%0A
+   %7D%0A      
       return
@@ -495,16 +495,22 @@
 l);%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 112