【Leetcode_easy】766. Toeplitz Matrix

problem

766. Toeplitz Matrix

solution1:

class Solution {
public:
    bool isToeplitzMatrix(vector<vector<int>>& matrix) {
        for(int i=0; i<matrix.size()-1; ++i)
        {
            for(int j=0; j<matrix[0].size()-1; ++j)
            {
                if(matrix[i][j] != matrix[i+1][j+1]) return false;
            }
        }
        return true;
    }
};

参考

1. Leetcode_easy_766. Toeplitz Matrix;

2. Grandyang;

原文地址:https://www.cnblogs.com/happyamyhope/p/11202577.html

时间: 2024-11-01 18:06:22

【Leetcode_easy】766. Toeplitz Matrix的相关文章

【Leetcode_easy】867. Transpose Matrix

problem 867. Transpose Matrix 参考1. Leetcode_easy_867. Transpose Matrix; 完 原文地址:https://www.cnblogs.com/happyamyhope/p/11215040.html

【poj3422】 Kaka&#39;s Matrix Travels

http://poj.org/problem?id=3422 (题目链接) 题意 N*N的方格,每个格子中有一个数,寻找从(1,1)走到(N,N)的K条路径,使得取到的数的和最大. Solution 同[codevs1277] 方格取数 代码 // poj3422 #include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio>

766. Toeplitz Matrix

A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now given an M x N matrix, return True if and only if the matrix is Toeplitz. Example 1: Input: matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]] Output: True Explanati

766. Toeplitz Matrix Toeplitz矩阵

A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now given an M x N matrix, return True if and only if the matrix is Toeplitz. Example 1: Input: matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]] Output: True Explanati

【leetcode】Search 2D Matrix

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right.The first integer of each row is greater than the last integer of the previous row

【LeetCode】542. 01 Matrix

Problem description Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell. The distance between two adjacent cells is 1. Example 1: Input: 0 0 0 0 1 0 0 0 0 Output: 0 0 0 0 1 0 0 0 0 Example 2: Input: 0 0 0 0 1 0 1 1 1

【LeetCode】-- 73. Set Matrix Zeroes

问题描述:将二维数组中值为0的元素,所在行或者列全set为0:https://leetcode.com/problems/set-matrix-zeroes/ 问题分析:题中要求用 constant space 的辅助空间.自然想到位优化.一个int可以存储31个元素的信息.这里刚好用到了字符串论文里面常用的优化处理方法.类似桶分的思想.好吧,这么看来这长时间的论文没白看. 附上代码: 1 void setZeroes(vector<vector<int>>& matrix

【UVA】11992 - Fast Matrix Operations(线段树模板)

基本的线段树,需要注意的是由于有set和add操作,懒惰标记下推的时候,优先递推set,之后递推add,每次执行set操作将add标记清0 WA了好几次是因为计算那一段的时候出问题了,可笑的是我对着模板找了一个多小时的错. #include<cstdio> #include<cmath> #include<queue> #include<stack> #include<map> #include<algorithm> using na

【UVA】11992 - Fast Matrix Operations(段树模板)

主体段树,要注意,因为有set和add操作,当慵懒的标志下推.递归优先set,后复发add,每次运行set行动add马克清0 WA了好几次是由于计算那一段的时候出问题了,可笑的是我对着模板找了一个多小时的错. #include<cstdio> #include<cmath> #include<queue> #include<stack> #include<map> #include<algorithm> using namespace