Index
Diagonal and Anti-Diagonal
562 Longest Line of Consecutive One in Matrix
涉及到对角线,反对角线时候,index应该如何取
假设matrix[n][m]
0 1 2 3
0 0 1 1 0
1 0 1 1 0
2 0 0 0 1
diag: (0, 1) (1 ,2) (2, 3)
可以这么想:从(0, 3)出发,到各个点的距离相同
adiag: (0, 2) (1, 1), (2, 0)
可以这么想:从(0, 0)出发,到各个点的距离相同
int[] diag = new int[n + m - 1]
int[] adiag = new int[n + m - 1]
for i
for j
diag[m - 1 - j + i] = ...
adiag[i + j]Handle the right bottom cell
Last updated