LeetCode 766. 托普利茨矩阵 Toeplitz Matrix (Easy)
作者:互联网
class Solution { public: bool isToeplitzMatrix(vector<vector<int>>& matrix) { for (int i = 0; i < matrix.size(); ++i) { if (!check(matrix, matrix[i][0], i, 0)) return false; } for (int i = 0; i < matrix[0].size(); ++i) { if (!check(matrix, matrix[0][i], 0, i)) return false; } return true; } bool check(vector<vector<int>>& matrix, int expectVal, int row, int col) { if (row >= matrix.size() || col >= matrix[0].size()) return true; if (matrix[row][col] != expectVal) return false; return check(matrix, expectVal, row + 1, col + 1); } };
标签:row,return,Matrix,int,766,托普,size,check,matrix 来源: https://www.cnblogs.com/ZSY-blog/p/12921896.html