A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element.
Now given an
M x N
matrix, return True if and only if the matrix is Toeplitz.
Note:
matrix
will be a 2D array of integers.matrix
will have a number of rows and columns in range[1, 20]
.matrix[i][j]
will be integers in range[0, 99]
.
Follow up:
- What if the matrix is stored on disk, and the memory is limited such that you can only load at most one row of the matrix into the memory at once?
- What if the matrix is so large that you can only load up a partial row into the memory at once?
一個矩陣如果每條對角線從左上到右下都是相同的元素,我們稱該矩陣為常對角。
現在給予一個
M x N
的矩陣,回傳該矩陣是否為常對角。
注意:
matrix
是二維的整數陣列.matrix
的直排和橫列個數範圍是[1, 20]
.matrix[i][j]
是一個整數,範圍是[0, 99]
.
進階:
- 如果矩陣儲存於硬碟中,且記憶體受到限制,你一次最多只能讀出矩陣中的一行到記憶體中,該怎麼辦?
- 如果矩陣很大,一次只能讀出部分的資料到記憶體中,該怎麼辦?
LeetCode
C++