257. Binary Tree Paths
Description
Given a binary tree, return all root-to-leaf paths.
Note: A leaf is a node with no children.
Constraints
Approach
Links
GeeksforGeeks
ProgramCreek
YouTube
Examples
Input: [1, 2, 3, null, 5]
Output: ["1->2->5", "1->3"]
Solutions
// Definition for a binary tree node.
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode() {}
TreeNode(int val) {
this.val = val;
}
TreeNode(int val, TreeNode left, TreeNode right) {
this.val = val;
this.left = left;
this.right = right;
}
}
Follow up
Last updated
Was this helpful?