首页 > 其他分享 >LeetCode:2319. 判断矩阵是否是一个 X 矩阵

LeetCode:2319. 判断矩阵是否是一个 X 矩阵

时间:2023-02-01 09:46:31浏览次数:40  
标签:false 2319 int 矩阵 flag grid bool LeetCode

class Solution {
public:
    bool checkXMatrix(vector<vector<int>>& grid) {
        int n = grid.size();
        bool flag = true;
        for(int i = 0;i < n;i++)
        {
            for(int j = 0;j < n;j++)
            {
                if(i == j || i + j == n - 1)
                {
                    if(grid[i][j] == 0)
                    {
                        flag = false;
                        break;
                    }
                }
                else
                {
                    if(grid[i][j] != 0)
                    {
                        flag = false;
                        break;
                    }
                }
            }
        }
        return flag;
    }
};

标签:false,2319,int,矩阵,flag,grid,bool,LeetCode
From: https://www.cnblogs.com/zjacky/p/17081512.html

相关文章