Practice Longest Univalue Path
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given the root of a binary tree, return 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. The length of the path between two nodes is represented by the number of edges between them.
Source: Longest Univalue Path on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
root = [5,4,5,1,1,null,5]
Output
2
# Example 2
Input
root = [1,4,5,4,4,null,5]
Output
2
Constraints
The number of nodes in the tree is in the range [0, 10^4].
-1000 <= Node.val <= 1000
The depth of the tree will not exceed 1000.
Related LeetCode Problems
Practice more problems similar to Longest Univalue Path.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.