题目简述:

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. UUID库

    If you cannot afford to use Boost, then there is a very minimal library that I implemented which sim ...

  2. 【先定一个小目标】Windows下Redis的安装使用

    Redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted set ...

  3. 使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串的长度超过了为 maxJsonLength 属性设置的值。

    解决办法是在web.config增加如下节点到<configuration>下 <system.web.extensions> <scripting> <we ...

  4. Shell脚本学习第二课·

    Shell文件包含 shell也可以包含外部脚本,语法格式如下: . filename 或 source filename 例如创建两个shell脚本. 脚本1:test1.sh url = &quo ...

  5. SQL Server群集知识介绍

    集群CLUSTER种类介绍 基于iSCSI的SQL Server 2012群集测试(一)--SQL群集安装 SQL Server群集如何在线检测 群集中的MS DTC分布式事务协调器 一.SQL Se ...

  6. 现代软件工程作业-- GitHub的学习

    1.注册github账号: 2.在github上面新建一个名为HelloWord的项目: 3.将本组的其他成员纳入到HelloWorld中: 4.复制远端仓库的地址: 5.在本地的git bash中使 ...

  7. Maven生命周期小记

    1.Maven生命周期是为了所有的构建过程进行抽象和统一.Maven从大量的项目和构建工具中学习和反思,总结了一套高度完善.易扩展的生命周期.这个生命周期包含了项目的清理.初始化.编译.测试.打包.集 ...

  8. file xxx from install of xxx conflicts with file from xxx

    执行安装 rpm -ivh lib64stdc++6-4.6.1-2-mdv2011.0.x86_64.rpm 时提示以下错误: warning: lib64stdc++6-4.6.1-2-mdv20 ...

  9. Linux下实现秒级的crontab定时任务

    crontab的格式如下 * * * * * command 分 时 日 月 周 命令 第1列表示分钟1-59 每分钟用*或者 */1表示 第2列表示小时1-23(0表示0点) 第3列表示日期1-31 ...

  10. 客户有两台windows服务器要做sql server双机切换

    基本架构 2 windows 2008 server:安装成域控制器,实现故障转移(虚拟ip访问,共享磁盘阵列卷链接主服务器),安装sqlserver2012 1磁盘阵列共享卷:数据库文件放于其中,两 ...