zoukankan      html  css  js  c++  java
  • 36. Valid Sudoku

    Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.

    The Sudoku board could be partially filled, where empty cells are filled with the character '.'.

    A partially filled sudoku which is valid.

    Note:
    A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated.

    用数组标记状态,row[i][j]表示第i行的数字j有没有出现过,col 和box同理

    class Solution {
    public:
        bool isValidSudoku(vector<vector<char>>& board) {
            int row[10][10] = {0}, col[10][10] = {0}, box[10][10] = {0};
              for(int i = 0; i < board.size(); i++)
              {
                  for(int j = 0; j < board[i].size(); j++)
                  {
                      if(board[i][j] != '.')
                      {
                          int x = board[i][j] - '0' - 1;
                          int k = i/3 + j/3;
                          if(row[i][x] || col[j][x] || box[k][x])
                              return false;
                          row[i][x] = col[j][x] = box[k][x] = 1;
                      }
                  }
              } 
              return true;
        }
    };
    如果有错误,请指出,谢谢
  • 相关阅读:
    Centos7.x做开机启动脚本
    贝叶斯方法之一
    R程序包
    c#调用R
    感悟--不可抗拒的行为
    IP等级
    词语
    关于editplus设置java和c#
    csc命令
    editplus配置csharp
  • 原文地址:https://www.cnblogs.com/Alruddy/p/7148349.html
Copyright © 2011-2022 走看看