#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. javascript 【封装AJAX】

    post function createXHR() { if (typeof XMLHttpRequest != 'undefined') { return new XMLHttpRequest(); ...

  2. Asp.Net长文件名下载的问题和解决办法

    在Asp.Net中写了一个附件上传和下载的程序,附件上传到数据库中,然后将附件的GUID保存起来,我们可以根据GUID来找到数据库中的附件,一般附件下载的代码是: <!--<br /> ...

  3. The executable was signed with invalid entitlements新设备run出现这个问题

    出现这个问题一般是新手不熟悉开发者发布流程造成地 一定要安开发者流程一步一步走 这样就不会出错了 注意这几个地方地设置 1.

  4. Spring-----自定义属性编辑器

    转载自:http://blog.csdn.net/hekewangzi/article/details/51712963

  5. Scala基础入门-3

    学习Scala——映射和元组 映射和和元组,也就是Maps和Tuples.Map这东西应该都挺明白的,就是键值对的集合.而元组,tuple,这东西并不是每个语言都有(Python中是有的,不过当时学的 ...

  6. jquery中的全局事件

    ajaxStart(callback):Ajax请求开始时触发该事件 ajaxSend(callback):Ajax请求发送前触发该事件 ajaxSuccess(callback):Ajax请求成功时 ...

  7. 6 支持向量机SVM

    注:理论部分参考:http://blog.csdn.net/v_july_v/article/details/7624837 (1)SVM是现成最好的分类器,这里“现成”指的是分类器不加修改即可直接使 ...

  8. Unicode其实是Latin1的扩展。只有一个低字节的Uncode字符其实就是Latin1字符——附各种字符编码表及转换表

    一.概念 1,ASCII             ASCII(American Standard Code for Information Interchange),中文名称为美国信息交换标准代码.是 ...

  9. TPen的7种Style和16种Mode

    //TPen 的主要属性有四: Color.Width.Style.Mode {Color: 颜色} {Width: 宽度; 默认是 1; 如果赋予 <= 0 的值, 会使用默认值} {Styl ...

  10. docker 私有仓库内容

    docker:/root# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES eb6d0ef3b9e2 linux123 ...