← 返回 apple 的题目列表Valid Sudoku
类型:online_judge
Problem: Valid Sudoku
Given a 9 x 9 Sudoku board, determine whether the current board is valid.
Only the filled cells need to be validated according to the following rules:
Each row must contain the digits 1-9 without repetition.
Each column must contain the digits 1-9 without repetition.
Each of the nine 3 x 3 sub-boxes must contain the digits 1-9 without repetition.
Empty cells are represented by the character '.' and should be ignored.
Notes:
A valid Sudoku board does not necessarily have to be solvable.
You only need to check whether the current filled cells violate any rule.
Input Format
The input contains 9 lines. Each line contains 9 characters, where each character is either '1' to '9' or '.'.
Output Format
Print:
true
if the board is valid, otherwise print:
false
Constraints
board.length == 9
board[i].length == 9
board[i][j] is a digit from '1' to '9' or '.'
Example 1
Input:
53..7....
6..195...
.98....6.
8...6...3
4..8.3..1
7...2...6
.6....28.
...419..5
....8..79
Output:
true
Example 2
Input:
83..7....
6..195...
.98....6.
8...6...3
4..8.3..1
7...2...6
.6....28.
...419..5
....8..79
Output:
false
Explanation: The digit 8 appears twice in the top-left 3 x 3 sub-box.
Example
Input
53..7....
6..195...
.98....6.
8...6...3
4..8.3..1
7...2...6
.6....28.
...419..5
....8..79
Output
true