当前位置:网站首页>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;
}
}
};
边栏推荐
- Kubernetes进阶部分学习笔记
- QML combines qsqltablemodel to dynamically load data MVC "recommended collection"
- leetcode-114:二叉树展开为链表
- [advanced drawing of single cell] 07. Display of KEGG enrichment results
- 【高等数学】【3】微分中值定理与导数的应用
- leetcode-919:完全二叉树插入器
- [today in history] July 17: Softbank acquired arm; The first email interruption; Wikimedia International Conference
- How to choose a microservice registration center?
- Chapter VI modified specification (SPEC) class
- [today in history] July 7: release of C; Chrome OS came out; "Legend of swordsman" issued
猜你喜欢

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

Mobile web layout method
![[today in history] July 8: PostgreSQL release; SUSE acquires the largest service provider of k8s; Activision Blizzard merger](/img/14/f2b68dbe4e6a9b8d89ed9ff38f5e11.png)
[today in history] July 8: PostgreSQL release; SUSE acquires the largest service provider of k8s; Activision Blizzard merger

程序的编译和运行

Character function and string function (2)

How much memory does bitmap occupy in the development of IM instant messaging?

火山引擎项亮:机器学习与智能推荐平台多云部署解决方案正式发布
![[today in history] June 28: musk was born; Microsoft launched office 365; The inventor of Chua's circuit was born](/img/bf/09ccf36caec099098a22f0e8b670bd.png)
[today in history] June 28: musk was born; Microsoft launched office 365; The inventor of Chua's circuit was born

增加 swap 空间

Myormframeworkjdbc review and problem analysis of user-defined persistence layer framework, and thought analysis of user-defined persistence layer framework
随机推荐
leetcode-79:单词搜索
Google guava is just a brother. What is the real king of caching? (glory Collection Edition)
Online random coin tossing positive and negative statistical tool
【高等数学】【4】不定积分
leetcode-6126:设计食物评分系统
Solution to oom exceptions caused by improper use of multithreading in production environment (supreme Collection Edition)
C language file reading and writing
Vulnhub | dc: 6 | [actual combat]
LeetCode通关:哈希表六连,这个还真有点简单
preprocessor directives
【高等数学】【3】微分中值定理与导数的应用
[tensorrt] trtexec tool to engine
[matlab] download originality documents based on oil monkey script and MATLAB
How much memory does bitmap occupy in the development of IM instant messaging?
[today in history] July 8: PostgreSQL release; SUSE acquires the largest service provider of k8s; Activision Blizzard merger
Unity VS—— VS中默认调试为启动而不是附加到Unity调试
【高等数学】【1】函数、极限、连续
Proxy实现mysql读写分离
Myormframeworkjdbc review and problem analysis of user-defined persistence layer framework, and thought analysis of user-defined persistence layer framework
Recommended books | essentials of industrial digital transformation: methods and Practice
