(matrix: Vec<Vec<i32>>)
| 1 | pub fn is_toeplitz_matrix(matrix: Vec<Vec<i32>>) -> bool { |
| 2 | let (m, n) = (matrix[0].len(), matrix.len()); |
| 3 | // 00 11 22 |
| 4 | // 01 12 23 |
| 5 | // 02 13 |
| 6 | // 03 |
| 7 | for y in 0..m { |
| 8 | let mut i = 0; |
| 9 | let mut j = y; |
| 10 | let prev = matrix[i][j]; |
| 11 | while j < m && i < n { |
| 12 | if matrix[i][j] != prev { return false; } |
| 13 | i += 1; |
| 14 | j += 1; |
| 15 | } |
| 16 | } |
| 17 | // 00 11 22 |
| 18 | // 10 21 |
| 19 | // 20 |
| 20 | for x in 0..n { |
| 21 | let mut i = x; |
| 22 | let mut j = 0; |
| 23 | let prev = matrix[i][j]; |
| 24 | while j < m && i < n { |
| 25 | if matrix[i][j] != prev { return false; } |
| 26 | i += 1; |
| 27 | j += 1; |
| 28 | } |
| 29 | } |
| 30 | true |
| 31 | } |
| 32 | |
| 33 | fn main() { |
| 34 | let matrix = vec![vec![1,2,3,4], vec![5,1,2,3], vec![9,5,1,2]]; |
nothing calls this directly
no outgoing calls
no test coverage detected