leetcode766+判断每一个元素的左上角是否和自己相等

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013554860/article/details/86439444

https://leetcode.com/problems/toeplitz-matrix/

//判断每个值是否等于左上角值
class Solution {
public:
    bool isToeplitzMatrix(vector<vector<int>>& matrix) {
        int row = matrix.size(), col = matrix[0].size();
        for(int i=1; i<row; i++){
            for(int j=0; j<col; j++){
                if(j-1>=0){
                    if(matrix[i][j]!=matrix[i-1][j-1]) return false;
                }
            }
        }
        return true;
    }
};

猜你喜欢

转载自blog.csdn.net/u013554860/article/details/86439444