码迷,mamicode.com
首页 > 其他好文 > 详细

[LeetCode] Longest Univalue Path 最长相同值路径

时间:2017-10-08 00:55:06      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:code   sam   node   input   pre   height   where   bsp   number   

 

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.

Example 1:

Input:

              5
             /             4   5
           / \             1   1   5

 

Output:

2

 

Example 2:

Input:

              1
             /             4   5
           / \             4   4   5

 

Output:

2

 

Note: The given binary tree has not more than 10000 nodes. The height of the tree is not more than 1000.

 

s

 

[LeetCode] Longest Univalue Path 最长相同值路径

标签:code   sam   node   input   pre   height   where   bsp   number   

原文地址:http://www.cnblogs.com/grandyang/p/7636259.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!