zoukankan      html  css  js  c++  java
  • leetcode Sudoku Solver python

    #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 '123456789': board[i][j] = k if isValid(i,j) and dfs(board): return True board[i][j] = '.' return False return True dfs(board)
  • 相关阅读:
    [ZZ]风险驱动的测试
    移动测试书籍推荐
    4月收藏
    Appium路线图及1.0正式版发布
    匿名吐槽和测试小道消息
    文章收藏
    [ZZ]最小化不可重现的bug
    华人世界——客家足迹行
    移动测试会第七期
    2月收藏
  • 原文地址:https://www.cnblogs.com/allenhaozi/p/5060066.html
Copyright © 2011-2022 走看看