valid_suduku

  • 2022-12-14
  • 浏览 (460)

valid_suduku.go 源码

package main

//有效的数独

func isValidSudoku(board [][]byte) bool {
	var hor, ver, grid [9][9]bool
	for i := 0; i < 9; i++ {
		for j := 0; j < 9; j++ {
			if board[i][j] != '.' {
				k := board[i][j] - '1'
				if hor[i][k] || ver[j][k] || grid[i/3*3+j/3][k] {
					return false
				}
				hor[i][k], ver[j][k], grid[i/3*3+j/3][k] = true, true, true
			}
		}
	}
	return true
}

你可能感兴趣的文章

best_time_buy_sell_stock

best_time_buy_sell_stock_ii

climb_stairs

0  赞