Implement a function to flatten a binary tree into a linked list in-place
HardProblem Statement
Implement a function to flatten a binary tree into a linked list in-place
Sample Input
Tree: 1 → 2 → 5 → 3 → 4 → 6
Sample Output
1 2 3 4 5 6
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
class TreeNode {
int val;
TreeNode left, right;
TreeNode(int x) { val = x; }
}
public class Main {
public static TreeNode flattenTree() {
// Create the binary tree here
// Your code here
return null;
}
}
Input
Tree: 1 → 2 → 5 → 3 → 4 → 6
Expected Output
1 2 3 4 5 6