1 class Solution 2 { 3 public: 4 bool isToeplitzMatrix(vector<vector<int>>& matrix) 5 { 6 bool result = true; 7 for(int i = matrix.size()-1;i >= 0;i --) 8 { 9 int init = matrix[i][0]; 10 for(int j = i+1,k = 1;j < matrix.size() && k < matrix[0].size();j ++,k ++) 11 { 12 if(matrix[j][k]!=init) 13 result = false; 14 } 15 } 16 17 for(int i = 1;i < matrix[0].size();i ++) 18 { 19 int init = matrix[0][i]; 20 for(int j=1,k=i+1;j < matrix.size() && k < matrix[0].size();j ++,k ++) 21 { 22 if(matrix[j][k]!=init) 23 result = false; 24 } 25 } 26 return result; 27 } 28 };
原文地址:https://www.cnblogs.com/Asurudo/p/9771063.html
时间: 2024-10-30 17:30:17