86: Longest univalue path of a binary tree

Given a binary tree, return length of the longest path where each node in the path has the same value

 

Example 1

Input:        8        
             / \       
            2   3      
           /   / \     
          4   3   3   

Output:  2

Explanation: 3 -> 3 -> 3

Example 2

Input:        1   
             / \  
            2   3 

Output: 0
Difficulty:Easy
Topic:Tree
Problem #:86