首页 > 代码库 > 36. Valid Sudoku
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; } };
36. Valid Sudoku
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。