【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 ...
随机推荐
- 差分进化算法 DE-Differential Evolution
差分进化算法 (Differential Evolution) Differential Evolution(DE)是由Storn等人于1995年提出的,和其它演化算法一样,DE是一种模拟生物进化 ...
- 关于MapReduce中自定义带比较key类、比较器类(二)——初学者从源码查看其原理
Job类 /** * Define the comparator that controls * how the keys are sorted before they * are pa ...
- 最新 Eclipse IDE下的Spring框架配置及简单实例
前段时间开始着手学习Spring框架,又是买书又是看视频找教程的,可是鲜有介绍如何配置Spring+Eclipse的方法,现在将我的成功经验分享给大家. 本文的一些源代码来源于码农教程:http:// ...
- 关于java中自增,自减,和拓展运算符的小讨论
java中运算符很多,但是能深入讨论的不算太多.这里我仅仅以++,*=为例做讨论. 例:++ i=0; i=i++ + ++i;//i=1 i=++i+i++;//i=2 i=i++ -++i;//i ...
- 【学习笔记】Struts2之配置处理结果
Action只是Struts2控制器的一部分,所以它不能直接生成对浏览者的响应.Action只负责生成响应的视图组件,通常是JSP页面,而Action会为JSP页面提供显示数据. Ac ...
- 通过代码自定义cell(cell的高度不一致,比如微博)
1.新建一个继承自UITableViewCell的类 2.重写initWithStyle:reuseIdentifier:方法 (先要调用父控件的nitWithStyle:reuseIdentifie ...
- 进程内部异步事件调用组件Async-Event
项目坐标:https://github.com/cncduLee/async-event async-event 进程内部异步事件调用组件 解决什么问题: 加速服务处理效率.提供进程级别的事件发布和异 ...
- SQL Server数据库定时自动备份
SQL Server 数据库定时自动备份[转] 在SQL Server中出于数据安全的考虑,所以需要定期的备份数据库.而备份数据库一般又是在凌晨时间基本没有数据库操作的时候进行,所以我们不可能要求 ...
- CSS实现可变行数垂直居中
<html> <head> <style> .vcenter { position: relative; height: 100%; width:50px; } . ...
- Java Native Interface 四--JNI中引用类型
本文是<The Java Native Interface Programmer's Guide and Specification>读书笔记 JNI支持将类实例和数组类型(如jobjec ...