Valid Sudoku

Medium

Topics
ArrayHash TableMatrix

Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be checked: each row, each column, and each 3 x 3 sub-box must contain no repeated digit 1-9. Empty cells are '.'. The board need not be solvable.

Example 1

Input:  board rows like "53..7...."
Output: true

Example 2

Input:  a board with two 8s in a column
Output: false

Constraints

  • board.length == 9
  • board[i].length == 9
  • board[i][j] is a digit 1-9 or '.'
Run ⌘' · Submit ⌘⏎