Flatten Binary Tree to Linked List
来源:互联网 发布:vps配置mysql数据库 编辑:程序博客网 时间:2024/04/29 16:47
Given a binary tree, flatten it to a linked list in-place.
For example,
Given
1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like:
1 \ 2 \ 3 \ 4 \ 5 \ 6
Solution Code:
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ typedef vector<int> List; class Solution {public: void flatten(TreeNode *root) { if(!root) return; if(root->left) { TreeNode *cur = root->left; while(cur->right) cur = cur->right; cur->right = root->right; root->right = root->left; root->left = NULL; } flatten(root->right); }};
- 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
- 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
- Flatten Binary Tree to Linked List
- Flatten Binary Tree to Linked List
- LeetCode - Flatten Binary Tree to Linked List
- 【leetcode】Flatten Binary Tree to Linked List
- Flatten Binary Tree to Linked List
- [LeetCode]Flatten Binary Tree to Linked List
- Flatten Binary Tree to Linked List
- Flatten Binary Tree to Linked List
- Flatten Binary Tree to Linked List
- 【最适合夏季的减肥食材】
- PLSQL Developer 注册码
- 栈的链式存储结构,逆波兰表达式
- java通讯录
- Hibernate get和load区别
- Flatten Binary Tree to Linked List
- 十、同步设备I/O与异步设备I/O(I/O完成端口)
- 什么是寄存器——汇编学习笔记(一)
- 四种格式的以太网帧结构
- java条形码的生成与扫描
- css padding margin初始化
- Spring 3 版本内容拾遗
- 继承
- ora-00844和ora-00851错误,大致是指SGA_MAX_SIZE设置过大