Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 109113e

Browse files
committed
Add solution #766
1 parent 3f9e5b3 commit 109113e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

0766-toeplitz-matrix.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* 766. Toeplitz Matrix
3+
* https://leetcode.com/problems/toeplitz-matrix/
4+
* Difficulty: Easy
5+
*
6+
* Given an m x n matrix, return true if the matrix is Toeplitz. Otherwise, return false.
7+
*
8+
* A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.
9+
*/
10+
11+
/**
12+
* @param {number[][]} matrix
13+
* @return {boolean}
14+
*/
15+
function isToeplitzMatrix(matrix) {
16+
const rows = matrix.length;
17+
const cols = matrix[0].length;
18+
19+
for (let r = 0; r < rows - 1; r++) {
20+
for (let c = 0; c < cols - 1; c++) {
21+
if (matrix[r][c] !== matrix[r + 1][c + 1]) {
22+
return false;
23+
}
24+
}
25+
}
26+
27+
return true;
28+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@
580580
763|[Partition Labels](./0763-partition-labels.js)|Medium|
581581
764|[Largest Plus Sign](./0764-largest-plus-sign.js)|Medium|
582582
765|[Couples Holding Hands](./0765-couples-holding-hands.js)|Hard|
583+
766|[Toeplitz Matrix](./0766-toeplitz-matrix.js)|Easy|
583584
783|[Minimum Distance Between BST Nodes](./0783-minimum-distance-between-bst-nodes.js)|Easy|
584585
784|[Letter Case Permutation](./0784-letter-case-permutation.js)|Medium|
585586
790|[Domino and Tromino Tiling](./0790-domino-and-tromino-tiling.js)|Medium|

0 commit comments

Comments
 (0)