leetcode543. Diameter of Binary Tree

2020-02-01
阅读 1 分钟
2k
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root.

leetcode480. Sliding Window Median

2019-11-24
阅读 5 分钟
1.8k
Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.

leetcode124. Binary Tree Maximum Path Sum

2017-08-13
阅读 2 分钟
2k
在这里和其它题目不一样的是,并非从根节点到叶节点的一条路径,而是从任意一个节点到任意一个节点的路径。其实在这里我们通过递归的方法可以发现以下几种场景:

leetcode114. Flatten Binary Tree to Linked List

2017-08-04
阅读 2 分钟
1.9k
题目要求 {代码...} 将一棵二叉树展开形成一棵链表形状的树。本质上是将该树转变成先序遍历后的样子。 思路一:非递归 如果我们从图形的角度来说,每一次都将当前节点的右子树拼接到左子节点的右子树下,再将左节点替换原来的右节点。所以这个例题一步步的操作如下: {代码...} 代码如下: {代码...} 思路二:递归 其实...