add: 221031

This commit is contained in:
Eatswap 2022-10-31 12:02:59 +08:00
parent bb83b31326
commit 18ecf286e4
Signed by: Eatswap
GPG Key ID: BE661106A1F3FA0B
1 changed files with 19 additions and 0 deletions

19
cpp/2210/221031.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <vector>
#include <algorithm>
/**
* 766. Toeplitz Matrix
*
* Given an m x n matrix, return true if the matrix is Toeplitz. Otherwise, return false.
* A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.
*/
class Solution {
public:
bool isToeplitzMatrix(const std::vector<std::vector<int>>& m) {
for (int i = 1; i < m.size(); ++i)
if (!std::equal(m[i].begin() + 1, m[i].end(), m[i - 1].begin()))
return false;
return true;
}
};