Company: Media.net
Difficulty: medium
Flatten Binary Tree to Linked List Given a binary tree A, flatten it to a linked list in-place. The left child of all nodes should be NULL. Constraints 1 ≤ size of tree ≤ 100000 Input Format First and only argument is the head of tree A. Output Format Return the linked-list after flattening. Examples Example 1: Input: 1 / \ 2 3 Output: 1 \ 2 \ 3 Example 2: Input: 1 / \ 2 5 / \ \ 3 4 6 Output: 1 \ 2 \ 3 \ 4 \ 5 \ 6 Code Template /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ TreeNode* Solution::flatten(TreeNode* A) { // Implement your solution here }