Skip to content

Commit

Permalink
Add Toeplitz Matrix solution
Browse files Browse the repository at this point in the history
  • Loading branch information
pilanop committed Mar 20, 2024
1 parent da00f7f commit 4006a77
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Div 3/Week 1/Progress Sheet/Toeplitz Matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Author: Khalid Mohammed
Problem: Toeplitz Matrix
Problem link: https://leetcode.com/problems/toeplitz-matrix/
Problem Description:
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.
Date Solved: Wed 20 Mar 2024
Time to Solve: 15 min
"""
from typing import List

matrix = [[1, 2, 3, 4], [5, 1, 2, 3], [9, 5, 1, 2]]


class Solution:
def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool:
for i in range(len(matrix) - 1):
for j in range(len(matrix[0]) - 1):
if matrix[i][j] != matrix[i + 1][j + 1]:
return False
return True


s = Solution()
print(s.isToeplitzMatrix(matrix))

0 comments on commit 4006a77

Please sign in to comment.