✅💯🔥Simple Code📌🚀| 🔥✔️Easy to understand🎯 | 🎓🧠Beginner friendly🔥| O(n) Time Complexity💀💯
Solution tuntun mosi ki photo ke baad hai. Scroll Down\n\n\n# Code\njava []\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int 
Solution tuntun mosi ki photo ke baad hai. Scroll Down\n![fd9d3417-20fb-4e19-98fa-3dd39eeedf43_1723794694.932518.png](https://assets.leetcode.com/users/images/a492c0ef-bde0-4447-81e6-2ded326cd877_1724187540.6168394.png)\n\n# Code\n```java []\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode() {}\n *     TreeNode(int val) { this.val = val; }\n *     TreeNode(int val, TreeNode left, TreeNode right) {\n *         this.val = val;\n *         this.left = left;\n *         this.right = right;\n *     }\n * }\n */\nclass Solution {\n    int total = 0;\n    public int pathSum(TreeNode root, int sum) {\n        if(root == null) return 0;\n        helper(root, sum, 0);\n        pathSum(root.left, sum);\n        pathSum(root.right, sum);\n        return total;\n    }\n\n    void helper(TreeNode root, int sum, long curr) {\n        if(root == null) return;\n        curr += root.val;\n        if(curr == sum) total++;\n        helper(root.left, sum, curr);\n        helper(root.right, sum, curr);\n    }\n}\n```\n![7be995b4-0cf4-4fa3-b48b-8086738ea4ba_1699897744.9062278.jpeg](https://assets.leetcode.com/users/images/fe5117c9-43b1-4ec8-8979-20c4c7f78d98_1721303757.4674635.jpeg)
['Tree', 'Depth-First Search', 'C', 'Binary Tree', 'Python', 'C++', 'Java', 'JavaScript']