#数独(すうどく,Sūdoku)是一种运用纸、笔进行演算的逻辑游戏。玩家需要根据9×9盘面上的已知数字,推理出所有剩余空格的数字,并满足每一行、每一列、每一个粗线宫内的数字均含1-9,不重复。
#数独盘面是个九宫,每一宫又分为九个小格。在这八十一格中给出一定的已知数字和解题条件,利用逻辑和推理,在其他的空格上填入1-9的数字。使1-9每个数字在每一行、每一列和每一宫中都只出现一次,所以又称“九宫格”。 # http://sudoku.com.au/TheRules.aspx class Solution(object):
def isValidSudoku(self, board):
"""
:type board: List[List[str]]
:rtype: bool
"""
def isValid(x,y,tmp):
for i in range(9):
if board[i][y] == tmp:
return False
for i in range(9):
if board[x][i] == tmp:
return False
for i in range(3):
for j in range(3):
if board[(x/3)*3+i][(y/3)*3+j] == tmp:
return False
for i in range(9):
for j in range(9):
if board[i][j] == '.':
continue
tmp=board[i][j]
board[i][j] = 'D'
if isValid(i,j,tmp) == False:
return False
return True

leetcode Valid Sudoku python的更多相关文章

  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

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

  3. LeetCode:Valid Sudoku,Sudoku Solver(数独游戏)

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

  4. LeetCode: Valid Sudoku 解题报告

    Valid SudokuDetermine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku boa ...

  5. [LeetCode] Valid Sudoku 验证数独

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

  6. [leetcode]Valid Palindrome @ Python

    原题地址:https://oj.leetcode.com/problems/valid-palindrome/ 题意: Given a string, determine if it is a pal ...

  7. [leetcode]Valid Number @ Python

    原题地址:http://oj.leetcode.com/problems/valid-number/ 题意:判断输入的字符串是否是合法的数. 解题思路:这题只能用确定有穷状态自动机(DFA)来写会比较 ...

  8. [Leetcode] valid sudoku 有效数独

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

  9. Leetcode | Valid Sudoku & Sudoku Solver

    判断valid,没有更好的方法,只能brute force. class Solution { public: bool isValidSudoku(vector<vector<char& ...

随机推荐

  1. 具体总结 Hive VS 传统关系型数据库

    本文思路,看图说话,一张图,清晰总结二者差别 以下对图中的各条做具体总结 1.查询语言 不做赘述 2.数据存储位置 不做赘述 3.数据格式 Hive:Hive 中未定义专门的数据格式,数据格式能够由用 ...

  2. nginx添加需要代理的域名 配置

    dap.cns.360buy.com为需要nginx代理的域名,被代理的端口为:8089,配置需要在${nginx_home}/conf/nginx.conf的文件中加入如下配置即可 upstream ...

  3. L10 安装网卡驱动

    一.安装网卡驱动 1. 检查各种依赖包是否安装 2. 安装 加载网卡驱动: ip:

  4. EC读书笔记系列之19:条款49、50、51、52

    条款49 了解new-handler的行为 记住: ★set_new_handler允许客户指定一个函数,在内存分配无法获得满足时被调用 ★Nothrow new是一个颇为局限的工具,∵其只适用于内存 ...

  5. dpkg, APT, aptitude常用命令

    Install dpkg --install, -i [deb] apt-get install [package] aptitude install [package] Remove dpkg -- ...

  6. tcp窗口滑动以及拥塞控制

    转自:http://blog.chinaunix.net/uid-26275986-id-4109679.html TCP协议作为一个可靠的面向流的传输协议,其可靠性和流量控制由滑动窗口协议保证,而拥 ...

  7. scroll运用、图片悬浮

    scroll 滚动条 长话短说进入正题: scrollTOP==0 内容置于顶部: scrollTOP()>=$(document).height-$(window).height 内容置于底部 ...

  8. List和Tuple类型

    list列表,list是一种有序的集合,可以随时添加和删除其中的元素,L=[]   索引从0开始,第一个元素的索引是0,第二个是1,倒数第一个是-1,倒数第二个是-2,以此类推,使用索引,不要越界   ...

  9. python threading 模块来实现多线程

    以多线程的方式向标准输出打印日志 #!/usr/bin/python import time import threading class PrintThread(threading.Thread): ...

  10. python--getitme\setitem 支持索引与分片

    1.想要自己定义的python对象支持索引与分片操作就要重载__getitem__\__setitem__这两个方法. 2.__getitme__(self,index) 这里的index参数可能类型 ...