当前位置:网站首页>Leetcode-114: expand binary tree into linked list
Leetcode-114: expand binary tree into linked list
2022-07-25 20:38:00 【Chrysanthemum headed bat】
leetcode-114: The binary tree is expanded into a list
subject
Topic linking
Give you the root node of the binary tree root , Please expand it into a single linked list :
The expanded single linked list should also be used TreeNode , among right The child pointer points to the next node in the list , The left sub pointer is always null .
The expanded single linked list should be the same as the binary tree The first sequence traversal Same order .
Example 1:

Input :root = [1,2,5,3,4,null,6]
Output :[1,null,2,null,3,null,4,null,5,null,6]
Example 2:
Input :root = []
Output :[]
Example 3:
Input :root = [0]
Output :[0]
Problem solving
Method 1 :
class Solution {
public:
void flatten(TreeNode* root) {
while(root){
TreeNode* p=root->left;
if(p){
while(p->right) p=p->right;
p->right=root->right;
root->right=root->left;
root->left=nullptr;
}
root=root->right;
}
}
};
边栏推荐
- Dataframe first performs grouping operation and then combines output
- leetcode-6125:相等行列对
- test
- Today's sleep quality record 75 points
- Jmeter——接口测试
- Key network protocols in tcp/ip four layer model
- [advanced mathematics] [1] function, limit, continuity
- MPI学习笔记(二):矩阵相乘的两种实现方法
- [workplace rules] it workplace rules | poor performance
- RF、GBDT、XGboost特征选择方法「建议收藏」
猜你喜欢

Docker builds redis cluster

智能电子界桩自然保护区远程监控解决方案
![[tensorrt] dynamic batch reasoning](/img/59/42ed0074de7162887bfe2c81891e20.png)
[tensorrt] dynamic batch reasoning

leetcode-155:最小栈

【高等数学】【4】不定积分

雷达水位计的工作原理及安装维护注意事项

ROS_ Rqt toolbox

How to obtain the subordinate / annotation information of KEGG channel
![[advanced mathematics] [6] differential calculus of multivariate functions](/img/9e/84fe6f74b58cbaabab1b6eed0df556.png)
[advanced mathematics] [6] differential calculus of multivariate functions

Has baozi ever played in the multi merchant system?
随机推荐
Increase swap space
JS scope and scope chain
[paper reading] unpaired image to image translation using cycle consistent advantageous networks
从底层结构开始学习FPGA(16)----PLL/MMCM IP的定制与测试
Question and answer 47: geeks have an appointment - the current monitoring system construction of CSC
【高等数学】【8】微分方程
Success factors of software R & D effectiveness measurement
Mobile web layout method
[today in history] July 3: ergonomic standards act; The birth of pioneers in the field of consumer electronics; Ubisoft releases uplay
Chinese son-in-law OTA Ono became the first Asian president of the University of Michigan, with an annual salary of more than 6.5 million!
String of sword finger offer question bank summary (II) (C language version)
第六章 修改规范(SPEC)类
wokerman 自定义写入日志文件
Interpretation of filter execution sequence source code in sprigboot
【高等数学】【6】多元函数微分学
Difference Between Accuracy and Precision
[today in history] July 17: Softbank acquired arm; The first email interruption; Wikimedia International Conference
[advanced mathematics] [6] differential calculus of multivariate functions
结构体,枚举类型与联合体
Implementation of simple registration and login
