1 class Solution { 2 public: 3 void flatten(TreeNode* root) { 4 if(!root) return; 5 flatten(root->left); 6 flatten(root->right); 7 8 TreeNode* right =
分类:
其他好文 时间:
2016-02-24 17:29:21
阅读次数:
118
Using DFS to traverse the tree. 4 cases for each node in the tree: case 1: it's a leaf node, set a pointer pointing to the node. We're reaching an end
分类:
其他好文 时间:
2016-01-30 09:37:00
阅读次数:
204
题目: 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
分类:
其他好文 时间:
2016-01-29 20:51:37
阅读次数:
215
题目:Givenabinarytree,flattenittoalinkedlistin-place.算法思路:其实该题目就是二叉树前序遍历的变形我代码沿用leetcode144.BinaryTreePreorderTraversal代码:classSolution(object):
defpreorderTraversal(self,root):
"""
:typeroot:TreeNode
:rtype:List[int]
"""
ifro..
分类:
编程语言 时间:
2016-01-24 19:55:41
阅读次数:
233
Question:https://leetcode.com/problems/flatten-binary-tree-to-linked-list/题目:Given a binary tree, flatten it to a linked list in-place.For example,Giv...
分类:
其他好文 时间:
2016-01-07 13:20:22
阅读次数:
175
list 是 Python 中使用最频繁的数据类型, 标准库里面有丰富的函数可以使用。不过,如果把多维列表转换成一维列表(不知道这种需求多不多),还真不容易找到好用的函数,要知道Ruby、Mathematica、Groovy中可是有flatten的啊。如果列表是维度少的、规则的,还算好办例如:li=...
分类:
编程语言 时间:
2016-01-05 12:39:09
阅读次数:
166
Flatten Binary Tree to Linked ListTotal Accepted:68105Total Submissions:228885Difficulty:MediumGiven a binary tree, flatten it to a linked list in-pla...
分类:
其他好文 时间:
2015-12-18 16:31:19
阅读次数:
85
Learn a few advanced reduction patterns: flatten allows you to merge a set of arrays into a single array, the dreaded flatmap allows you to convert an...
分类:
编程语言 时间:
2015-12-17 06:54:29
阅读次数:
297
http://www.ituring.com.cn/article/131442https://twitter.github.io/scala_school/zh_cn/collections.html#flatten如果不了解map,flatMap,zip和reduce函数,你就不能真正地谈论sc...
分类:
其他好文 时间:
2015-11-26 13:01:41
阅读次数:
199
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened t...
分类:
其他好文 时间:
2015-11-09 22:38:44
阅读次数:
237