114. Flatten Binary Tree to Linked List
题目大意
Given the root of a binary tree, flatten the tree into a “linked list”:
- The “linked list” should use the same
TreeNode
class where the right child pointer points to the next node in the list and the left child pointer is always null. - The “linked list” should be in the same order as a pre-order traversal of the binary tree.
中文释义
给定一个二叉树的根节点,将树展平成一个“链表”:
- “链表”应该使用相同的
TreeNode
类,其中右子指针指向列表中的下一个节点,左子指针始终为 null。 - “链表”应该与二叉树的前序遍历顺序相同。
示例
示例 1:
输入: root
= [1,2,5,3,4,null,6]
输出: [1,null,2,null,3,null,4,null,5,null,6]