Java Solution for LeetCode's Path Sum Problem

Day 40 of #100DaysOfLeetCode 💻✅ Solved #112. Path Sum problem in Java. Approach: • Used recursion to traverse the binary tree from root to leaf • Subtracted the current node value from the targetSum at each step • Checked whether the current node is a leaf node (no left and right children) • If the remaining sum becomes 0 at the leaf node, returned true • Otherwise continued checking the left and right subtrees recursively Performance: ✓ Runtime: 1 ms (Beats 6.06% submissions) ✓ Memory: 45.18 MB (Beats 27.94% submissions) Key Learning: ✓ Practiced root-to-leaf traversal in binary trees ✓ Learned how to track the remaining sum during recursion ✓ Improved understanding of recursive tree problem solving Learning one problem every single day 🚀 #Java #LeetCode #DSA #ProblemSolving #CodingJourney #100DaysOfCode

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories