Given a 01 matrix M, find the longest line of consecutive one in the matrix. The line could be horizontal, vertical, diagonal or anti-diagonal.
Example:
Input:
[[0,1,1,0],
[0,1,1,0],
[0,0,0,1]]
Output: 3
Hint: The number of elements in the given matrix will not exceed 10,000.
解法1:DP, O(nm)
用一个三维数组记录每一个格子上4个方向的最长的个数。同时更新一下最长的值即可。
C++
Java