298. Binary Tree Longest Consecutive Sequence
298. Binary Tree Longest Consecutive Sequence
Description
Given the root
of a binary tree, return the length of the longest consecutive sequence path .
A consecutive sequence path is a path where the values increase by one along the path.
Note that the path can start at any node in the tree, and you cannot go from a node to its parent in the path.
Example 1:
![](https://assets.leetcode.com/uploads/2021/03/14/consec1-1-tree.jpg)
1 | Input: root = [1,null,3,2,4,null,null,null,5] |
Example 2:
![](https://assets.leetcode.com/uploads/2021/03/14/consec1-2-tree.jpg)
1 | Input: root = [2,null,3,2,null,1] |
Constraints:
- The number of nodes in the tree is in the range
[1, 3 * 10^4]
. -3 * 10^4 <= Node.val <= 3 * 10^4
Hints/Notes
- traverse the tree
Solution
Language: C++
1 | /** |