0
点赞
收藏
分享

微信扫一扫

摸鱼日记2.20

非常帅气的昵称吧 2022-02-20 阅读 69

学习目标:

数组,简单内容。

学习内容:

有效的数独

使用memset进行初始化。

class Solution {
public:
  bool isValidSudoku(vector<vector<char>> &board) {
    int rows[9][9];
    int columns[9][9];
    int subboxes[3][3][9];

    memset(rows, 0, sizeof(rows));
    memset(columns, 0, sizeof(columns));
    memset(subboxes, 0, sizeof(subboxes));

    for (int i = 0; i < 9; ++i) {
      for (int j = 0; j < 9; ++j) {
        if (board[i][j] != '.') {
          int index = board[i][j] - '1';
          rows[i][index]++;
          columns[j][index]++;
          subboxes[i / 3][j / 3][index]++;
          if (rows[i][index] > 1 || columns[j][index] > 1 ||
              subboxes[i / 3][j / 3][index] > 1)
            return false;
        }
      }
    }
    return true;
  }
};

田田感冒了,用了一大包纸,呜呜。
但是很爱田田,田田也很爱我。嘻嘻。爱死她了。

举报

相关推荐

摸鱼日记2.15

摸鱼日记2.5

摸鱼日记1.24

摸鱼日记1.19

摸鱼日记1.31

摸鱼日记1.29

2.20kill、raise、abort函数

0 条评论