687. Longest Univalue Path
题目描述
Given a binary tree, find the length of the longest path where each node in the path has the same value. This path may or may not pass through the root.
Note: The length of path between two nodes is represented by the number of edges between them.
|
|
|
|
Note: The given binary tree has not more than 10000 nodes. The height of the tree is not more than 1000.
题目大意
求二叉树节点值全部相等的最长路径,路径不一定通过根节点。
解题思路
递归遍历左右子树,寻找左右子树节点值全部相等的最长路径。
代码
|
|