leetcode先刷_Valid Sudoku
我没有看到这个问题,这使其在现货需求数独,害怕一直没敢做。后来我发现原来的标题就是这么简单。推断现在只有数字全不符合的就可以了棋盘上的形势的要求。
是不是正确的三个周期。。人是不能满意地看到每一行。每列装不满意,每个小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的更多相关文章
- [LeetCode] 036. Valid Sudoku (Easy) (C++)
指数:[LeetCode] Leetcode 解决问题的指数 (C++/Java/Python/Sql) Github: https://github.com/illuz/leetcode 036. ...
- LeetCode:36. Valid Sudoku,数独是否有效
LeetCode:36. Valid Sudoku,数独是否有效 : 题目: LeetCode:36. Valid Sudoku 描述: Determine if a Sudoku is valid, ...
- [leetcode]_Valid Sudoku
中间被启程日本的面试弄的没有静下心来复习算法.这样不好,基本功是硬道理.逐步恢复刷题. 题目:给一个数独(九宫格)中的一些数字,判断该数独是否有效. 即按照数独的规则,判断其行.列.小九格中是否有重复 ...
- Leetcode 笔记 36 - Sudoku Solver
题目链接:Sudoku Solver | LeetCode OJ Write a program to solve a Sudoku puzzle by filling the empty cells ...
- [Leetcode][Python]37: Sudoku Solver
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 37: Sudoku Solverhttps://oj.leetcode.co ...
- [LeetCode] 36. Valid Sudoku 验证数独
Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to th ...
- LeetCode 36 Valid Sudoku
Problem: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board ...
- 【leetcode】Valid Sudoku
题目简述: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board cou ...
- [leetcode]算法题目 - Sudoku Solver
最近,新加坡总理李显龙也写了一份代码公布出来,大致瞧了一眼,竟然是解数独题的代码!前几天刚刚写过,数独主要算法当然是使用回溯法.回溯法当时初学的时候在思路上比较拧,不容易写对.写了几个回溯法的算法之后 ...
随机推荐
- LeetCode Algorithm 07_Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to ...
- HttpWatch--简介及使用技巧
一 概述: HttpWatch强大的网页数据分析工具.集成在Internet Explorer工具栏.包括网页摘要.Cookies管理.缓存管理.消息头发送/接受.字符查询.POST 数据和目录管理功 ...
- Nginx- 实现跨域访问
https://blog.csdn.net/m_nanle_xiaobudiu/article/details/80688740
- [Nuxt] Build a Vue.js Form then use Vuex Actions to Post to an API in Nuxt
The default behavior of submitting an HTML form is to reload the page. You can use the Vue.js @submi ...
- php实现数值的整数次方
php实现数值的整数次方 一.总结 没有考虑到指数为负数的情况 二.php实现数值的整数次方 题目描述: 给定一个double类型的浮点数base和int类型的整数exponent.求base的exp ...
- 【36.86%】【codeforces 558B】Amr and The Large Array
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Booth算法
Booth算法 算法描述(载自维基百科) 对于N位乘数Y,布斯算法检查其2的补码形式的最后一位和一个隐含的低位,命名为y-1,初始值为0.对于yi, i = 0, 1, ..., N - 1,考察yi ...
- swift学习第一天:认识swift以及swift的常量和变量
一:认识swift // 1.导入框架 //#import <UIKit/UIKit.h> import UIKit // 2.定义一个标识符 // int a = 10; // swif ...
- ios开发之Quartz2D 四:画饼图
#import "PieView.h" @implementation PieView - (void)drawRect:(CGRect)rect { // Drawing cod ...
- 【t053】整数去位
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 键盘输入一个高精度的正整数N,去掉其中任意M个数字后剩下的数字按原左右次序将组成一个新的正整数.编程对 ...