2
* Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode3
* right; TreeNode() {} TreeNode(int val) { this.val = val; } TreeNode(int val, TreeNode left,4
* TreeNode right) { this.val = val; this.left = left; this.right = right; } }9
public int longestUnivaluePath(TreeNode root) {14
public int lup(TreeNode root) {18
int left = lup(root.left);19
int right = lup(root.right);22
if (root.left != null && root.val == root.left.val) {25
if (root.right != null && root.val == root.right.val) {28
maxLen = Math.max(maxLen, leftMax + rightMax);29
return Math.max(leftMax, rightMax);