Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 10. 31. 23:45

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

 

Toeplitz Matrix - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

오예 easy 난이도~
문제도 안보고 일단 풀수 있겠다 싶은 마음이 듦.

막상 풀어보니 그렇게 쉬운 문제까지는 아닌데, 그냥 base 를 잘 잡고 풀면 쉽게 풀리긴 함

class Solution:
    def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool:
        x, y = len(matrix[0]), len(matrix)
        visited = [[False for _ in range(x)] for __ in range(y)]
        
        for m in range(y):
            for n in range(x):
                if visited[m][n] or m+1 == y or n+1 == x:
                    continue
                
                if matrix[m][n] != matrix[m+1][n+1]:
                    return False
                    
                visited[m][n] = True
                
        return True
반응형