114. Flatten Binary Tree to Linked List
来源:互联网 发布:定陶知行劳务电话 编辑:程序博客网 时间:2024/05/29 18:07
/*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 \ 6click to show hints.Hints:If you notice carefully in the flattened tree, each node's right child points to the next node of a pre-order traversal.*//** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {private: TreeNode* pre=NULL;public: void flatten(TreeNode* root) { if(!root) return; flatten(root->right); flatten(root->left); root->left=NULL; root->right=pre; pre=root; }};
阅读全文
0 0
- 114. Flatten Binary Tree to Linked List
- 114. Flatten Binary Tree to Linked List
- 114. Flatten Binary Tree to Linked List
- 114. Flatten Binary Tree to Linked List
- 114. Flatten Binary Tree to Linked List
- 114. Flatten Binary Tree to Linked List
- 114. Flatten Binary Tree to Linked List
- 114. Flatten Binary Tree to Linked List
- 114. Flatten Binary Tree to Linked List
- 114. Flatten Binary Tree to Linked List
- 114. Flatten Binary Tree to Linked List
- 114. Flatten Binary Tree to Linked List
- 114. Flatten Binary Tree to Linked List
- 114. Flatten Binary Tree to Linked List
- 114. Flatten Binary Tree to Linked List
- 114. Flatten Binary Tree to Linked List
- 114. Flatten Binary Tree to Linked List
- 114. Flatten Binary Tree to Linked List
- UE4(四)获取UE4源码以及使用源码编译引擎
- HDU 6203 ping ping ping lca 线段树成段更新
- 微软2017年预科生计划在线编程笔试-#1489 : Legendary Items
- Java String.split()用法小结
- sublime的各种问题
- 114. Flatten Binary Tree to Linked List
- eclipse建立webservice服务端与客户端
- LeetCode.153
- codewar-6kyu-Vasya
- 2017年执业药师考试中药炮制学常见考点小结
- 解决session超时的时候会出现双层登录窗口的问题
- 【跟踪】基于mean shift的目标跟踪算法
- Python2.7升级到3.0 HTMLTestrunner报错解决方法
- MFC获取框架,视图,文档指针