mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-27 21:58:57 +01:00
40 lines
No EOL
1.4 KiB
Ruby
40 lines
No EOL
1.4 KiB
Ruby
# Challenge name: Valid Sudoku
|
|
|
|
# Determine if a 9 x 9 Sudoku 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 of the grid must contain the digits 1-9 without repetition.
|
|
|
|
# @param {Character[][]} board
|
|
# @return {Boolean}
|
|
|
|
#
|
|
# Approach 1:
|
|
#
|
|
# Time Complexity:
|
|
#
|
|
def is_valid_sudoku(board)
|
|
end
|
|
|
|
board = [["5","3",".",".","7",".",".",".","."]
|
|
,["6",".",".","1","9","5",".",".","."]
|
|
,[".","9","8",".",".",".",".","6","."]
|
|
,["8",".",".",".","6",".",".",".","3"]
|
|
,["4",".",".","8",".","3",".",".","1"]
|
|
,["7",".",".",".","2",".",".",".","6"]
|
|
,[".","6",".",".",".",".","2","8","."]
|
|
,[".",".",".","4","1","9",".",".","5"]
|
|
,[".",".",".",".","8",".",".","7","9"]]
|
|
print(is_valid_sudoku(board))
|
|
# => true
|
|
board = [["8","3",".",".","7",".",".",".","."]
|
|
,["6",".",".","1","9","5",".",".","."]
|
|
,[".","9","8",".",".",".",".","6","."]
|
|
,["8",".",".",".","6",".",".",".","3"]
|
|
,["4",".",".","8",".","3",".",".","1"]
|
|
,["7",".",".",".","2",".",".",".","6"]
|
|
,[".","6",".",".",".",".","2","8","."]
|
|
,[".",".",".","4","1","9",".",".","5"]
|
|
,[".",".",".",".","8",".",".","7","9"]]
|
|
print(is_valid_sudoku(board))
|
|
# => false |