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.
题意:判断是否满足数独的条件。
思路:判断同一行,,列,格子时候满足不同的数,数组判重就行了
class Solution {public:bool isValidSudoku(vector<vector<char> > &board) {int rows[10][10], cols[10][10], block[10][10];memset(rows, 0, sizeof(rows));memset(cols, 0, sizeof(cols));memset(block, 0, sizeof(block));for (int i = 0; i < 9; i++)for (int j = 0; j < 9; j++) {if (board[i][j] == '.') continue;int cur = board[i][j] – '0';if (rows[i][cur] || cols[j][cur] || block[i/3*3+j/3][cur])return false;rows[i][cur] = cols[j][cur] = block[i/3*3+j/3][cur] = 1;}return true;}};
找一个让心里安静和干净的地方,