首页 > 其他 > 详细

longest consecutive path

时间:2018-09-11 15:30:06      阅读:169      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!