0
Leetcode Problem 257. Binary Tree Paths
257. Binary Tree Paths
AI Mock Interview
Leetcode Solutions
Recursive Depth-First Search
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Define a helper function that accepts a node and the current path string.
If the current node is null, return without doing anything.
Append the current node's value to the path string.
If the current node is a leaf (no children), add the path string to the list of paths.
If the current node has a left child, recursively call the helper function with the left child and the updated path string.
If the current node has a right child, recursively call the helper function with the right child and the updated path string.
Invoke the helper function with the root node and an empty path string to start the DFS.
Iterative Depth-First Search with Stack
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Code Diffs Compare
Full Screen
Copy Answer Code
Loading...
Sign in with LinkedIn
Sign in with Github
OR
Sign in with Email link