【LeetCode 面试经典150题】114. Flatten Binary Tree to Linked List 二叉树展开为链表

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]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值