2319. Check if Matrix Is X-Matrix

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2319

class Solution:
    def checkXMatrix(self, grid: List[List[int]]) -> bool:
        for i, row in enumerate(grid):
            for j, v in enumerate(row):
                if i == j or i + j == len(grid) - 1:
                    if v == 0:
                        return False
                elif v:
                    return False
        return True