Skip to content
LC-2319 Easy LeetCode

2319. Check if Matrix Is X-Matrix

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 65% Topics: Array, Matrix
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n^2)
# Space: O(1)

# array
class Solution(object):
    def checkXMatrix(self, grid):
        """
        :type grid: List[List[int]]
        :rtype: bool
        """
        return all((i-j == 0 or i+j == len(grid)-1) == (grid[i][j] != 0) for i in xrange(len(grid)) for j in xrange(len(grid[0])))

Solution from kamyu104/LeetCode-Solutions · MIT

Similar questions