我没有看到这个问题,这使其在现货需求数独,害怕一直没敢做。后来我发现原来的标题就是这么简单。推断现在只有数字全不符合的就可以了棋盘上的形势的要求。

是不是正确的三个周期。。人是不能满意地看到每一行。每列装不满意,每个小3*3的格男人不能满足孩子。每个小3*3格子我是用求得左上角的方法来验证的。

事实上认为数独难另一个原因是记得他在编程之美上出现过。。

那上面讨论的主要是如何构造一个数独。详细记不太清楚了,印象最深的是,要想保证有解,最好的办法是先用置换法生成一个解,然后去掉这个解中的一些位置。

class Solution {
public:
bool isValidSudoku(vector<vector<char> > &board) {
bool vis[10];
for(int start=0;start<9;start++){
int i = start/3, j = start%3;
memset(vis, 0, sizeof(vis));
for(int k=0;k<9;k++){
int ii=i*3+k/3, jj=j*3+k%3;
if(board[ii][jj] == '.')
continue;
if(vis[board[ii][jj]-'0'])
return false;
else
vis[board[ii][jj]-'0'] = 1;
}
}
for(int i=0;i<9;i++){
memset(vis, 0, sizeof(vis));
for(int j=0;j<9;j++){
if(board[i][j]=='.')
continue;
if(vis[board[i][j]-'0'])
return false;
vis[board[i][j]-'0'] = 1;
}
}
for(int i=0;i<9;i++){
memset(vis, 0, sizeof(vis));
for(int j=0;j<9;j++){
if(board[j][i]=='.')
continue;
if(vis[board[j][i]-'0'])
return false;
vis[board[j][i]-'0'] = 1;
}
}
return true;
}
};

版权声明:本文博主原创文章,博客,未经同意不得转载。

leetcode先刷_Valid Sudoku的更多相关文章

  1. [LeetCode] 036. Valid Sudoku (Easy) (C++)

    指数:[LeetCode] Leetcode 解决问题的指数 (C++/Java/Python/Sql) Github: https://github.com/illuz/leetcode 036. ...

  2. LeetCode:36. Valid Sudoku,数独是否有效

    LeetCode:36. Valid Sudoku,数独是否有效 : 题目: LeetCode:36. Valid Sudoku 描述: Determine if a Sudoku is valid, ...

  3. [leetcode]_Valid Sudoku

    中间被启程日本的面试弄的没有静下心来复习算法.这样不好,基本功是硬道理.逐步恢复刷题. 题目:给一个数独(九宫格)中的一些数字,判断该数独是否有效. 即按照数独的规则,判断其行.列.小九格中是否有重复 ...

  4. Leetcode 笔记 36 - Sudoku Solver

    题目链接:Sudoku Solver | LeetCode OJ Write a program to solve a Sudoku puzzle by filling the empty cells ...

  5. [Leetcode][Python]37: Sudoku Solver

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 37: Sudoku Solverhttps://oj.leetcode.co ...

  6. [LeetCode] 36. Valid Sudoku 验证数独

    Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to th ...

  7. LeetCode 36 Valid Sudoku

    Problem: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board ...

  8. 【leetcode】Valid Sudoku

    题目简述: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board cou ...

  9. [leetcode]算法题目 - Sudoku Solver

    最近,新加坡总理李显龙也写了一份代码公布出来,大致瞧了一眼,竟然是解数独题的代码!前几天刚刚写过,数独主要算法当然是使用回溯法.回溯法当时初学的时候在思路上比较拧,不容易写对.写了几个回溯法的算法之后 ...

随机推荐

  1. IOS获取preferreces偏好设置plistname名称的方法

    //获取preferreces偏好设置plistname名称的方法1 -(NSArray*)loadSpecifiersFromPlistName:(NSString*)plistName targe ...

  2. 分析Net 内存对象

    .Net 内存对象分析   在生产环境中,通过运行日志我们会发现一些异常问题,此时,我们不能直接拿VS远程到服务器上调试,同时日志输出的信息无法百分百反映内存中对象的状态,比如说我们想查看进程中所有的 ...

  3. JSP中多条件判断

    <c:if test="${result_map.connNew ne null and result_map.connNew ne 0}"> </c:if> ...

  4. [Angular2] Build reuseable template with ngTemplateOutlet

    We can build a template, use this template and pass in different context to make it reuseable: <t ...

  5. 用python的库监听鼠标程序测试,有程序,有现象

    程序如下: # -*- coding: utf-8 -*- import pythoncom, pyHook  def OnMouseEvent(event):   print 'MessageNam ...

  6. spring-如何在项目启动的情况下获取Bean实例

    十年阿里,就只剩下这套Java开发体系了 >>>   大家都知道,项目启动的时候,spring读取xml文件,将配置的bean 或者 注解下的controller service d ...

  7. 驱动程序调试方法之printk——printk的原理与直接使用

    1.基本原理 (1)在UBOOT里设置console=ttySAC0或者console=tty1 这里是设置控制终端,tySAC0 表示串口, tty1 表示lcd(2)内核用printk打印 内核就 ...

  8. before/after伪类常见用法

    1.清除浮动 ; } /*IE6/IE7*/ .clearfix:after{ display: block; content: "clear"; ; clear: both; o ...

  9. 【24.34%】【codeforces 560D】Equivalent Strings

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  10. dnf游戏外怪原理

    dnf游戏外怪原理 一.总结 一句话总结:用钩子,修改内存.找到存储数据的内存,修改内存的执行代码达到修改数据的目的,修改了数据之后再改回来. 1.如何找到存储数据的内存? 然后数据变化,用软件找变化 ...