Solution to Leetcode 687: Longest Univalue Path
This problem is very similar to lc543, which is about finding the longest edge path in a tree. You can just copy over that code, and add 2 lines in it. Here we are doing the same thing as in lc543, however, when we encounter a non-matching child. We treat it as null. For example, here the longest path at root node is highlighted below in red with 6 edges. ...