![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
二叉树
云苓玉竹
目前是一名算法工程师
展开
-
The minimum depth The maximum path sum path sum II
leetcode 上的四个问题 1 The minimum depth 2 The maximum depth 3 path sum 4 path sum II 本文一次性放到一个函数中运行: 其定义为: The minimum depth is the number of nodes along the shortest path from the root原创 2016-03-29 16:01:41 · 301 阅读 · 0 评论 -
Binary Tree Maximum Path Sum
/* 二叉树: 本题是为了解决对于任意一个Binary Tree , 我们要求出其最大路径和,即是哪条路径节点值得和最大, 将和返回即可。 本题难点在于对于BT,他可以从任意node 开始,也可以 在any node stop.因此,我们可以采用深度优先搜索法(DFS) 我们算出左右子树的数值l,r,如果l>0,表明左子树对整个结果有利,可以加上, 同理如果r>0,表明右子树也有利,原创 2016-03-29 17:30:02 · 352 阅读 · 0 评论 -
二叉树的构造与遍历
本文用于二叉树的遍历与构造: /* 二叉树的构造及遍历 遍历 1 / \ 2 3 / \ / \ 4 5 6 7 / \ / 8 9 10 先序: 1 根 2 左 3 右 (1,2,3,4,5都是根(父节点)) 上述序列:1 2 4 8 9 5 10 3 6 7 中序: 1 左 2 根 3 右 序列:8 4 9 2 10 5 1 6 3 7 后原创 2016-03-28 14:34:30 · 291 阅读 · 0 评论