[JAVA] Clean Code, Easy to Understand
\nclass Solution {\n\t\n\tint paths = 0;\n\t\n\tprivate void helper (TreeNode root, int sum) {\n\t\t\n\t\tif (root != null && root.val == sum) {\n\t\t\t++paths;
```\nclass Solution {\n\t\n\tint paths = 0;\n\t\n\tprivate void helper (TreeNode root, int sum) {\n\t\t\n\t\tif (root != null && root.val == sum) {\n\t\t\t++paths;\n\t\t}\n\t\tif (root != null) {\n\t\t\tsum -= root.val;\n\t\t\thelper (root.left, sum);\n\t\t\thelper (root.right, sum);\n\t\t}\n\t}\n\t\n\tpublic int pathSum (TreeNode root, int sum) {\n\t\t\n\t\tif (root == null) {\n\t\t\treturn 0;\n\t\t}\n\t\thelper (root, sum);\n\t\tpathSum (root.left, sum);\n\t\tpathSum (root.right, sum);\n\t\treturn paths;\n\t}\n}\n```\n\nPlease help to **UPVOTE** if this post is useful for you.\nIf you have any questions, feel free to comment below.\n**HAPPY CODING :)\nLOVE CODING :)**\n
[]