114. Flatten Binary Tree to Linked List
Description
Given a binary tree, flatten it to a linked list in-place.
Constraints
Approach
Links
YouTube
Examples
Input: [1, 2, 5, 3, 4, null, 6]

Output: [1, null, 2, null, 3, null, 4, null, 5, null, 6]

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?