Question: 5. Given a binary tree, return all root-to-leaf paths (depth-first). Write the description and code of the algorithm Example Input: {1,2,3,#,5) public class TreeNode {
5. Given a binary tree, return all root-to-leaf paths (depth-first). Write the description and code of the algorithm Example Input: {1,2,3,#,5) public class TreeNode { Output: ["1->2->5","1-3"] public int val; public TreeNode left, right; Explanation: public TreeNodeant val) { this.val - val; this.left this.right null; 2 3 } 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
