题目简述:

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. 美国usan数据库——PDF提取

    QQ:231469242 原创 单个PDF内容提取 # -*- coding: utf-8 -*- """ io.open() is the preferred, hig ...

  2. python发送邮件

    python发送邮件(无附件) ======================================================= #!/usr/bin/env python#coding ...

  3. 计算机常用dos命令

    一.简单的dos命令 win+R ------打开"运行"窗口 cmd ------回车进入"dos"命令窗口 ipconfig ------查看本机ip地址 ...

  4. Vue.js简单实践

    直接上代码,一个简单的新闻列表页面(.cshtml): @section CssSection{ <style> [v-cloak] { display: none; } </sty ...

  5. Could not find or load main class org.gradle.wrapper.GradleWrapperMain解决办法

    解决办法: gradlew is the gradle wrapper executable - batch script on windows and shell script elsewhere. ...

  6. js实现继承的5种方式 (笔记)

    js实现继承的5种方式 以下 均为 ES5 的写法: js是门灵活的语言,实现一种功能往往有多种做法,ECMAScript没有明确的继承机制,而是通过模仿实现的,根据js语言的本身的特性,js实现继承 ...

  7. 修改context 和 enforce?

    http://jingyan.baidu.com/article/8ebacdf0cce84849f75cd57b.html 可以彻底的 关闭 selinux, selinux的配置文件 在 /etc ...

  8. AD域控制器通过组策略禁止USB设备

    问题:域环境下如何禁用USB口设备? 第一种:用传统的办法,在Bios中禁用USB. 第二种: 微软技术支持回答:根据您的需求, Windows识别USB设备主要通过两个文件,一个是Usbstor.p ...

  9. JavaScript 智能社 完美运动框架

    简约版: function getStyle(obj, name) { if(obj.currentStyle) { return obj.currentStyle[name]; } else { r ...

  10. Velocity 局部定制模板

    Velocity介绍 Velocity是一个基于java的template engine.它允许Web designer引用Java Code中定义的方法.Web designer可以和Java工程师 ...