본문 바로가기
Problem Solving/LeetCode

[LeetCode] 766. Toeplitz Matrix - Java

by graycode 2026. 10. 12.

• 문제 링크

 

Toeplitz Matrix - LeetCode

Can you solve this real interview question? 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.   Example 1:

leetcode.com

 

• 풀이 코드

public class Solution {

    public boolean isToeplitzMatrix(int[][] matrix) {
        int r = matrix.length, c = matrix[0].length;
        for (int i = 1; i < r; i++) for (int j = 1; j < c; j++) if (matrix[i][j] != matrix[i - 1][j - 1]) return false;

        return true;
    }

}

댓글