LeetCode Day 85: Binary Tree Paths with DFS Recursion

🔥 Day 85 of my LeetCode Journey 🔥 📘 Problem: 257. Binary Tree Paths 🎯 Difficulty: Easy 🔹 Problem Statement: Given the root of a binary tree, return all root-to-leaf paths in any order. A leaf is a node with no children. 🔹 Approach Used: Use recursion to traverse the tree If a node is a leaf → add its value as a path For non-leaf nodes: Recursively get paths from left subtree Recursively get paths from right subtree Append current node value with "->" to each child path Collect and return all paths 🔹 Key Concepts: Recursion Depth-First Search (DFS) Tree traversal String manipulation 🔹 Learning: This problem strengthens understanding of DFS traversal and how to build paths dynamically during recursion. It also shows how to combine results from subtrees efficiently. ✅ Status: Accepted (Runtime: 5 ms) 📌 Break problems into smaller subproblems — recursion does the rest 🚀 #LeetCode #Day82 #Java #BinaryTree #DFS #Recursion #DSA #ProblemSolving

  • text

To view or add a comment, sign in

Explore content categories