766. Toeplitz Matrix Easy

@problem@discussion
#Array#Matrix



1/**
2 * [766] Toeplitz Matrix
3 *
4 * Given an m x n matrix, return true if the matrix is Toeplitz. Otherwise, return false.
5 * A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.
6 *  
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2020/11/04/ex1.jpg" style="width: 322px; height: 242px;" />
9 * Input: matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]
10 * Output: true
11 * Explanation:
12 * In the above grid, the diagonals are:
13 * "[9]", "[5, 5]", "[1, 1, 1]", "[2, 2, 2]", "[3, 3]", "[4]".
14 * In each diagonal all elements are the same, so the answer is True.
15 * 
16 * Example 2:
17 * <img alt="" src="https://assets.leetcode.com/uploads/2020/11/04/ex2.jpg" style="width: 162px; height: 162px;" />
18 * Input: matrix = [[1,2],[2,2]]
19 * Output: false
20 * Explanation:
21 * The diagonal "[1, 2]" has different elements.
22 * 
23 *  
24 * Constraints:
25 * 
26 * 	m == matrix.length
27 * 	n == matrix[i].length
28 * 	1 <= m, n <= 20
29 * 	0 <= matrix[i][j] <= 99
30 * 
31 *  
32 * Follow up:
33 * 
34 * 	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?
35 * 	What if the matrix is so large that you can only load up a partial row into the memory at once?
36 * 
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/toeplitz-matrix/
41// discuss: https://leetcode.com/problems/toeplitz-matrix/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46    pub fn is_toeplitz_matrix(matrix: Vec<Vec<i32>>) -> bool {
47        false
48    }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn test_766() {
59    }
60}
61


Back
© 2025 bowen.ge All Rights Reserved.