longest consecutive path
Posted tobeabetterpig
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了longest consecutive path相关的知识,希望对你有一定的参考价值。
Given a 2D matrix containing all positive and distinct integers in the range [1, N^2], compute the longest path containing consecutive integers in this matrix. return the length of the longest path.
[2,1,3]
[4,9,5]
[8,7,6]
7,8 len=2 7-->2
traverse from 6, 6->7 len of 6 = 2+1=3
The answer is 4 (path is [5,6,7,8]).
N=3 3*3=9
[1,3,5,8]
[2,4,6,7]
[11,12,13,15]
[10,9,14,16]
The answer is 6 (path is [9,10,11,12,13,14]).
以上是关于longest consecutive path的主要内容,如果未能解决你的问题,请参考以下文章
LC.298.Binary Tree Longest Consecutive Sequence