题目简述:

Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.

The Sudoku board could be partially filled, where empty cells are filled with the character '.'.

A partially filled sudoku which is valid.

Note:

A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated.

解题思路:

把三个都判断下就完了

class Solution:
# @param board, a 9x9 2D array
# @return a boolean
def isValidSudoku(self, board):
#row
for i in range(9):
vis = [False] * 9
for j in range(9):
if board[i][j] == '.':
continue
if vis[int(board[i][j])-1] == True:
return False
else:
vis[int(board[i][j])-1] = True #colum
for i in range(9):
vis = [False] * 9
for j in range(9):
if board[j][i] == '.':
continue
if vis[int(board[j][i])-1] == True:
return False
else:
vis[int(board[j][i])-1] = True #block
for i in range(0,9,3):
for j in range(0,9,3):
vis = [False] * 9
for k in range(i,3+i):
for l in range(j,3+j):
if board[k][l] == '.':
continue
if vis[int(board[k][l])-1] == True:
return False
else:
vis[int(board[k][l])-1] = True return True

【leetcode】Valid Sudoku的更多相关文章

  1. 【LeetCode】 Valid Sudoku

    Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...

  2. 【leetcode】Valid Sudoku (easy)

    题目:就是判断已有的数字是否冲突无效,若无效返回flase 有效返回true 不要求sudo可解 用了char型的数字,并且空格用‘.'来表示的. 思路:只要分别判断横向 竖向 3*3小块中的数字是否 ...

  3. 【Leetcode】【Easy】Valid Sudoku

    Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...

  4. 【LeetCode】37. Sudoku Solver

    Sudoku Solver Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are i ...

  5. 【leetcode】Valid Palindrome

    题目简述: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...

  6. 【leetcode】Valid Parentheses

    题目简述: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if th ...

  7. 【leetcode】Valid Number

    Valid Number Validate if a given string is numeric. Some examples:"0" => true" 0.1 ...

  8. 【题解】【字符串】【Leetcode】Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  9. 【LeetCode】- Valid Palindrome(右回文)

    [ 问题: ] Given a string, determine if it is a palindrome, considering only alphanumeric characters an ...

随机推荐

  1. Django基础,Day6 - 单元测试tests

    在django项目app目录下,有个tests.py,我们通常可以直接在这文件中写我们的单元测试代码. test for a model 根据前面章节的操作步骤下来,在Question Model中有 ...

  2. JS 获取CSS属性值

    obj: 元素对象 attribute: 属性 返回值:该对象这个属性的值 function getDefaultStyle(obj,attribute){ // 返回最终样式函数,兼容IE和DOM, ...

  3. C数组下标越界

    之前总听说C语言的各种毛病,今天算是遇到一个:数组下标越界 事情经过 两段完成不相干的代码,一段是测温度的,一段是测转速的.两段代码单独运行都没有问题,但是若运行测转速的代码,测温度的数据就会发生错误 ...

  4. 总是多次出现 那个同样的 权限错误 _storage_write_error_, 所以一开始就把机器设好setenforce 0

    把根目录下的所有文件/目录, 都设为权限777. 好像没有必要把所有的东西, 都设为777, 实际上问题是由selinux引起的, 所以, 只要把相应的目录, 不一定是所有的目录, 只是要写入内容的目 ...

  5. Oracle的表锁死以及解锁

    Oracle的表锁死以及解锁 oracle 查看锁死的表,锁死的进程. select sess.sid, sess.serial#, lo.oracle_username, lo.os_user_na ...

  6. hdu2211杀人游戏

    Problem Description 不知道你是否玩过杀人游戏,这里的杀人游戏可没有法官,警察之类的人,只有土匪,现在已知有N个土匪站在一排,每个土匪都有一个编号,从1到N,每次杀人时给定一个K值, ...

  7. 面向对象编程(OOP)

    什么是面向对象编程,对于面向对象编程与面向过程编程的解释随处可见,个人认为对面向对象编程解释最好的一个定义是:依赖倒转原则是面向对象编程的标志,面向对象编程是一种思想,无论使用哪一种编程语言,如果在编 ...

  8. 记录vmware虚拟机安装的时候一些注意

    1.选择从哪里安装操作系统的时候,要选择第三项过一会安装,不要选择第一项. 2.点击开始三角形的时候,选择中文安装或者英文安装,但键盘布局要选择USA,美国. 3.安装vmwaretools的时候,执 ...

  9. C# Async, Await and using statements

    Async, Await 是基于 .NEt 4.5架构的, 用于处理异步,防止死锁的方法的开始和结束, 提高程序的响应能力.比如: Application area           Support ...

  10. 虚函数的使用 以及虚函数与重载的关系, 空虚函数的作用,纯虚函数->抽象类,基类虚析构函数使释放对象更彻底

    为了访问公有派生类的特定成员,可以通过讲基类指针显示转换为派生类指针. 也可以将基类的非静态成员函数定义为虚函数(在函数前加上virtual) #include<iostream> usi ...