码迷,mamicode.com
首页 > 其他好文 > 详细

longest consecutive path

时间:2018-09-11 16:11:19      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:osi   ret   from   rom   tin   positive   ini   put   contain   

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

标签:osi   ret   from   rom   tin   positive   ini   put   contain   

原文地址:https://www.cnblogs.com/tobeabetterpig/p/9627590.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!