Leetcode-766 Toeplitz Matrix(托普利茨矩阵)

 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 };

 

posted @ 2018-10-11 10:34  Asurudo  阅读(174)  评论(0编辑  收藏  举报