Leetcode-114. Flatten Binary Tree to Linked List
来源:互联网 发布:136书屋下载软件 编辑:程序博客网 时间:2024/06/07 09:09
题目
Given a binary tree, flatten it to a linked list in-place.
For example,
Given
1
/ \
2 5
/ \ \
3 4 6
The flattened tree should look like:
1
\
2
\
3
\
4
\
5
\
6
代码
class Solution {public: void flatten(TreeNode *root) { if(root == NULL) return; while(root) { if(root->left) { TreeNode *t = root->left; while(t->right) t = t->right; t->right = root->right; root->right = root->left; root->left = NULL; } root = root->right; } }};
0 0
- LeetCode: Flatten Binary Tree to Linked List
- LeetCode Flatten Binary Tree to Linked List
- LeetCode: Flatten Binary Tree to Linked List
- [Leetcode] Flatten Binary Tree to Linked List
- [LeetCode] Flatten Binary Tree to Linked List
- Leetcode: Flatten Binary Tree to Linked List
- leetcode Flatten Binary Tree to Linked List
- LeetCode Flatten Binary Tree to Linked List
- LeetCode - Flatten Binary Tree to Linked List
- 【leetcode】Flatten Binary Tree to Linked List
- [LeetCode]Flatten Binary Tree to Linked List
- [Leetcode]Flatten Binary Tree to Linked List
- [leetcode]Flatten Binary Tree to Linked List
- LeetCode-Flatten Binary Tree to Linked List
- [leetcode] Flatten Binary Tree to Linked List
- LeetCode - Flatten Binary Tree to Linked List
- LeetCode:Flatten Binary Tree to Linked List
- [LeetCode] Flatten Binary Tree to Linked List
- 编辑距离(动态规划经典)
- 面试题this的指向整理
- RecycleView加载不同条目
- 基础练习 Sine之舞
- __str__ returned non-string (type int)
- Leetcode-114. Flatten Binary Tree to Linked List
- MPI散播(MPI_Scatter)
- 求x!中v素因子的个数
- tomcat优化
- effect C++ 复制对象时勿忘其每一个成分
- 素数分解
- 设计模式笔记(java版)
- 18.模拟 CAS 算法
- 1006. Sign In and Sign Out (25)