Advertisement
unknown_0711

Untitled

Jan 9th, 2023
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. class Solution {
  2. public boolean isValidSudoku(char[][] board) {
  3. boolean[][] rows = new boolean[9][9];
  4. boolean[][] columns = new boolean[9][9];
  5. boolean[][] squares = new boolean[9][9];
  6. for (int i = 0; i < board.length; i++) {
  7. for (int j = 0; j < board[i].length; j++) {
  8. if (board[i][j] == '.') {
  9. continue;
  10. }
  11. int num = board[i][j] - '1';
  12. if (rows[i][num]) {
  13. return false;
  14. }
  15. rows[i][num] = true;
  16. if (columns[j][num])return false;
  17. columns[j][num] = true;
  18. if (squares[(i / 3) * 3 + j / 3][num])
  19. return false;
  20. squares[(i / 3) * 3 + j / 3][num] = true;
  21. }
  22. }
  23. return true;
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement