原题描述Description:
Sudoku Background
Sudoku is a game played on a 9x9 grid. The goal of the game is to fill all cells of the grid with digits from 1 to 9, so that each column, each row, and each of the nine 3x3 sub-grids (also known as blocks) contain all of the digits from 1 to 9.
(More info at: http://en.wikipedia.org/wiki/Sudoku)
Sudoku Solution Validator
Write a function validSolution that accepts a 2D array representing a Sudoku board, and returns true if it is a valid solution, or false otherwise. The cells of the sudoku board may also contain 0's, which will represent empty cells. Boards containing one or more zeroes are considered to be invalid solutions.
题意就是让同学们做一个数独验证器,能够检测输入的一个简单二位数组(board)是否是一个已经完成(没有0,0表示未完成的空格)且正确(符合数独规则,即横竖、9个小宫格里面都有且只有1-9)
这道题目从大方向上来说应该用验证性的方法,即有错就return False,排错到最后return True
下面是几种思路:
1.活用sorted()函数可以免去排序的麻烦
correct = [1, 2, 3, 4
1087




被折叠的 条评论
为什么被折叠?



