L619 Binary Tree Longest Consecutive Sequence III
PreviousL614 Binary Tree Longest Consecutive Sequence IINext117 Populating Next Right Pointers in Each Node II
Last updated
Was this helpful?
Last updated
Was this helpful?
It's follow up problem for
Given ak-ary tree
, find the length of the longest consecutive sequence path.
The path could be start and end at any node in the tree
Example
An example of test data: k-ary tree5<6<7<>,5<>,8<>>,4<3<>,5<>,3<>>>
, denote the following structure:
跟614的结构基本一样,还是把这层的孩子节点全求一遍,然后统计up/down的max。最后加起来跟孩子的max比较。同理up和down不会在同一branch取得up max & down max,所以只要加起来就ok了。感觉这个childMaxLen也可以初始化为0。