【leetcode】Valid Sudoku
题目简述:
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的更多相关文章
- 【LeetCode】 Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...
- 【leetcode】Valid Sudoku (easy)
题目:就是判断已有的数字是否冲突无效,若无效返回flase 有效返回true 不要求sudo可解 用了char型的数字,并且空格用‘.'来表示的. 思路:只要分别判断横向 竖向 3*3小块中的数字是否 ...
- 【Leetcode】【Easy】Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...
- 【LeetCode】37. Sudoku Solver
Sudoku Solver Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are i ...
- 【leetcode】Valid Palindrome
题目简述: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...
- 【leetcode】Valid Parentheses
题目简述: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if th ...
- 【leetcode】Valid Number
Valid Number Validate if a given string is numeric. Some examples:"0" => true" 0.1 ...
- 【题解】【字符串】【Leetcode】Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- 【LeetCode】- Valid Palindrome(右回文)
[ 问题: ] Given a string, determine if it is a palindrome, considering only alphanumeric characters an ...
随机推荐
- 美国usan数据库——PDF提取
QQ:231469242 原创 单个PDF内容提取 # -*- coding: utf-8 -*- """ io.open() is the preferred, hig ...
- python发送邮件
python发送邮件(无附件) ======================================================= #!/usr/bin/env python#coding ...
- 计算机常用dos命令
一.简单的dos命令 win+R ------打开"运行"窗口 cmd ------回车进入"dos"命令窗口 ipconfig ------查看本机ip地址 ...
- Vue.js简单实践
直接上代码,一个简单的新闻列表页面(.cshtml): @section CssSection{ <style> [v-cloak] { display: none; } </sty ...
- 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. ...
- js实现继承的5种方式 (笔记)
js实现继承的5种方式 以下 均为 ES5 的写法: js是门灵活的语言,实现一种功能往往有多种做法,ECMAScript没有明确的继承机制,而是通过模仿实现的,根据js语言的本身的特性,js实现继承 ...
- 修改context 和 enforce?
http://jingyan.baidu.com/article/8ebacdf0cce84849f75cd57b.html 可以彻底的 关闭 selinux, selinux的配置文件 在 /etc ...
- AD域控制器通过组策略禁止USB设备
问题:域环境下如何禁用USB口设备? 第一种:用传统的办法,在Bios中禁用USB. 第二种: 微软技术支持回答:根据您的需求, Windows识别USB设备主要通过两个文件,一个是Usbstor.p ...
- JavaScript 智能社 完美运动框架
简约版: function getStyle(obj, name) { if(obj.currentStyle) { return obj.currentStyle[name]; } else { r ...
- Velocity 局部定制模板
Velocity介绍 Velocity是一个基于java的template engine.它允许Web designer引用Java Code中定义的方法.Web designer可以和Java工程师 ...