Sudoku Solver

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 {
public:

bool isValid(vector<vector<char> > &board,int i0,int j0)
{
char target=board[i0][j0];

;i<;i++)
{
if(i==i0) continue;
if(board[i][j0]==target)
{
return false;
}
}

;j<;j++)
{
if(j==j0) continue;
if(board[i0][j]==target)
{
return false;
}
}

*;i<i0/*+;i++)
{

*;j<j0/*+;j++)
{
if(i==i0&&j==j0) continue;
if(board[i][j]==target)
{
return false;
}
}
}

return true;
}

bool scanPos(vector<vector<char> > &board,int pos)
{
) return true;

bool flag=false;
;
;

if(board[i0][j0]!='.')
{
);
}

;j<=;j++)
{

board[i0][j0]='+j;
if(isValid(board,i0,j0))
{
))
{
flag=true;
break;
}
}
}

if(flag==false)
{
board[i0][j0]='.';
return false;
}
else
{
return true;
}
}

void solveSudoku(vector<vector<char> > &board) {
scanPos(board,);
}
};```

【leetcode】Sudoku Solver的更多相关文章

1. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

2. 【Leetcode】Pascal&amp;#39;s Triangle II

Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

3. 53. Maximum Subarray【leetcode】

53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...

4. 27. Remove Element【leetcode】

27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...

5. 【LeetCode】Repeated DNA Sequences 解题报告

[题目] All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: &quo ...

6. 【LeetCode】Min Stack 解题报告

[题目] Design a stack that supports push, pop, top, and retrieving the minimum element in constant tim ...

7. 【LeetCode】#7 Reverse Integer

[Question] Reverse digits of an integer. Example: x = 123, return 321 x = -123, return -321 [My Solu ...

8. 【LeetCode】#344 Reverse String

[Question] Write a function that takes a string as input and returns the string reversed. Example: G ...

9. 【LeetCode】#1 Two Sum

[Question] Given an array of integers, return indices of the two numbers such that they add up to a ...

随机推荐

1. 以冒泡排序为例--malloc/free 重定向stdin stdout

esort.c 代码如下,可关注下mallloc/free,freopen重定向的用法,排序为每轮将最小的数放在最前面: #include<stdio.h> #include<mal ...

2. JPA入门

JPA是什么 JPA全称Java Persistence API,是一组用于将数据存入数据库的类和方法的集合.JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化 ...

3. 离线安装eclipse的svn插件

原文:http://blog.sina.com.cn/s/blog_8e037f440101ebmz.html 连接不到外网情况下,在eclipse中安装svn插件. 两种方法: 首先下载安装到ecl ...

4. 【转】清理Kylin的中间存储数据(HDFS &amp; HBase Tables)

http://blog.csdn.net/jiangshouzhuang/article/details/51290399 Kylin在创建cube过程中会在HDFS上生成中间数据.另外,当我们对cu ...

5. jquery插件jquery.LightBox.js之点击放大图片并左右点击切换图片（仿相册插件）

该插件乃本博客作者所写,目的在于提升作者的js能力,也给一些js菜鸟在使用插件时提供一些便利,老鸟就悠然地飞过吧. 此插件旨在实现目前较为流行的点击放大图片并左右点击切换图片的效果,您可以根据自己的实 ...

6. ios消息

Class typedef struct objc_class *Class; struct objc_class { Class isa OBJC_ISA_AVAILABILITY; #if !__ ...

7. centOS设置zookeeper开机自动启动

在/etc/rc.local文件中追加: # java_homeexport JAVA_HOME=/opt/java/jdk1.7.0_75# zookeeper/home/cent2014/zook ...

8. HDU 1166敌兵布阵+NOJv2 1025: Hkhv love spent money（线段树单点更新区间查询）

敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

9. 2013ACM/ICPC亚洲区南京站现场赛——题目重现

GPA http://acm.hdu.edu.cn/showproblem.php?pid=4802 签到题,输入两个表,注意细心点就行了. #include<cstdio> #inclu ...

10. Linux服务器的常用备份方法

系统备份是系统管理工作中十分重要的一个环切,本文详细介绍了各种Linux系统的备份方法,相信对大家的日常管理工作有所帮助. 备份是一项重要的工作,但是很多人没有去做.一旦由于使用不当造成数据丢失,备份 ...