Flatten Binary Tree to Linked List
来源:互联网 发布:淘宝双十一数据 编辑:程序博客网 时间:2024/06/06 09:50
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 \ 6Hints: If you notice carefully in the flattened tree, each node's right child points to the next node of a pre-order traversal.
将左子树插入到root和其右子树之间。
void flatten(TreeNode *root){ if (root==NULL) return; TreeNode* left = root->left; TreeNode* right = root->right; if (left) { root->right = left; root->left = NULL; TreeNode* rightmost = left; while(rightmost->right) { rightmost = rightmost->right; } rightmost->right = right; } flatten(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
- 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
- OCP-1Z0-051 第46题 约束和索引
- nfs简单使用
- HDC,CDC,CWindowDC,CClientDC,CPaintDC基础
- 从零开始学HTML(六)--HTML 段落
- ATO SOLUTION NAND/MCP/SPI
- Flatten Binary Tree to Linked List
- 轻松解决 MyEclipse、Eclipse 编译时提示 @Override The method of type must override a superclass method 即 @Overr
- 第一章 2. CPaintDC 和 消息映射机制
- LGP970刷机心得
- FZU2169:防守阵地 I
- 错排公式
- memset
- Flip Game
- 第一次解题报告