JAVA SOLUTION


  • 0
    N
    • ...
      class Solution {
      int val =0;
      public int pathSum(TreeNode root, int sum) {

        if(root == null )
            return 0;
        path(root,sum);
        return val;          
      

      }

      void path(TreeNode root,int sum){
      if(root == null) return;
      ps(root,sum);
      path(root.left,sum);
      path(root.right,sum);

      }
      void ps(TreeNode root,int sum){
      if(root == null) return;
      if(sum == root.val){
      val++;
      }
      ps(root.left,sum - root.val);
      ps(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.