#the define of Sudoku is on this link : http://sudoku.com.au/TheRules.aspx

Write a program to solve a Sudoku puzzle by filling the empty cells.


Empty cells are indicated by the character '.'.


You may assume that there will be only one unique solution.



A sudoku puzzle...




...and its solution numbers marked in red.


class Solution(object):
def solveSudoku(self, board):
"""
:type board: List[List[str]]
:rtype: void Do not return anything, modify board in-place instead.
"""
def isValid(x,y):
tmp=board[x][y]
board[x][y]='D'
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
board[x][y]=tmp
return True
def dfs(board):
for i in range(9):
for j in range(9):
if board[i][j] == '.':
for k in '':
board[i][j] = k
if isValid(i,j) and dfs(board):
return True
board[i][j] = '.'
return False
return True
dfs(board)

leetcode Sudoku Solver python的更多相关文章

  1. [LeetCode] Sudoku Solver 求解数独

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  2. Leetcode: Sudoku Solver

    July 19, 2015 Problem statement: Write a program to solve a Sudoku puzzle by filling the empty cells ...

  3. LEETCODE —— Sudoku Solver

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  4. [LeetCode] Sudoku Solver(迭代)

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  5. leetcode—sudoku solver

    1.题目描述 Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicate ...

  6. [LeetCode] Sudoku Solver 解数独,递归,回溯

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  7. [Leetcode][Python]37: Sudoku Solver

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 37: Sudoku Solverhttps://oj.leetcode.co ...

  8. Leetcode 笔记 36 - Sudoku Solver

    题目链接:Sudoku Solver | LeetCode OJ Write a program to solve a Sudoku puzzle by filling the empty cells ...

  9. leetcode 37. Sudoku Solver 36. Valid Sudoku 数独问题

    三星机试也考了类似的题目,只不过是要针对给出的数独修改其中三个错误数字,总过10个测试用例只过了3个与世界500强无缘了 36. Valid Sudoku Determine if a Sudoku ...

随机推荐

  1. hdu - 4709 - Herding

    题意:给出N个点的坐标,从中取些点来组成一个多边形,求这个多边形的最小面积,组不成多边形的输出"Impossible"(测试组数 T <= 25, 1 <= N < ...

  2. 运用Autoconf和Automake生成Makefile的学习之路

    作为Linux下的程序开发人员,大家一定都遇到过Makefile,用make命令来编译自己写的程序确实是很方便.一般情况下,大家都是手工写一个简单Makefile,如果要想写出一个符合自由软件惯例的M ...

  3. ORACLE表空间管理方式segment和extent

    A permanent tablespace contains persistent schema objects. Objects in permanent tablespaces are stor ...

  4. jps无法获取到tomcat(java)进程

    一.问题描述: Ubuntu 10.10版本,同个JDK 1.6版本,启动tomcat后,使用jps无法获取本机Java进程. 二.jps工作原理: 1. java进程启动时,若没有指定 -Djava ...

  5. LVS客户端启动脚本

    在设置LVS客户端时,如果我们使用手工设置的话会比较麻烦.现在我们直接使用脚本来启动lvs-client就OK了,下面是一个简单的脚本. VIP地址:10.0.0.230,把文件放到/etc/init ...

  6. Cortex-M3和Cortex-M4 Fault异常应用之二 ----- Fault处理函数的实现

    在项目处于调试期间,Fault处理程序可能只是一个断点指令,调试器遇到这个指令后停止程序的运行.默认情况下,由于非硬Fault被禁能,所有发生的非Fault都会上访成硬Fault,因此只要在硬Faul ...

  7. CC++初学者编程教程(8) VS2013配置编程助手与QT

    1. 2. 配置编程助手 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26 ...

  8. 在linux下读取bmp文件头的完整代码。

    呵呵,贴在这里记录一下. [cpp] view plaincopy #include<stdio.h> #include<string.h> #include<sys/t ...

  9. Qt学习--部件深入--烤猪蹄

    1,进程条--向用户显示程序的当前状态,向用户提示该任务需要多长时间才能够完成. Qt-ProgressBar创建进程条,QProgressBar,为了使进程条担当起进程指示功能,需要执行定义进程条的 ...

  10. Aix6.1安装openssh

    一.软件下载 1.官方网站下载: openssl IBM官方网站下载:https://www14.software.ibm.com/webapp/iwm/web/reg/download.do?sou ...