java.lang.Object
g2301_2400.s2319_check_if_matrix_is_x_matrix.Solution

public class Solution extends Object
2319 - Check if Matrix Is X-Matrix.<p>Easy</p> <p>A square matrix is said to be an <strong>X-Matrix</strong> if <strong>both</strong> of the following conditions hold:</p> <ol> <li>All the elements in the diagonals of the matrix are <strong>non-zero</strong>.</li> <li>All other elements are 0.</li> </ol> <p>Given a 2D integer array <code>grid</code> of size <code>n x n</code> representing a square matrix, return <code>true</code> <em>if</em> <code>grid</code> <em>is an X-Matrix</em>. Otherwise, return <code>false</code>.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2022/05/03/ex1.jpg" alt="" /></p> <p><strong>Input:</strong> grid = [[2,0,0,1],[0,3,1,0],[0,5,2,0],[4,0,0,2]]</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> Refer to the diagram above.</p> <p>An X-Matrix should have the green elements (diagonals) be non-zero and the red elements be 0.</p> <p>Thus, grid is an X-Matrix.</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2022/05/03/ex2.jpg" alt="" /></p> <p><strong>Input:</strong> grid = [[5,7,0],[0,3,1],[0,5,0]]</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> Refer to the diagram above.</p> <p>An X-Matrix should have the green elements (diagonals) be non-zero and the red elements be 0.</p> <p>Thus, grid is not an X-Matrix.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == grid.length == grid[i].length</code></li> <li><code>3 <= n <= 100</code></li> <li><code>0 <= grid[i][j] <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • checkXMatrix

      public boolean checkXMatrix(int[][] grid)