题目:

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

  1. Each row must contain the digits 1-9 without repetition.
  2. Each column must contain the digits 1-9 without repetition.
  3. Each of the 9 3x3 sub-boxes of the grid must contain the digits 1-9 without repetition.

分析:

每一行,每一列没有相同的数字,每一个3*3的小正方形中也没有相同的数字。可以使用数组,map,set等等来判断。

程序:

class Solution {
public:
bool isValidSudoku(vector<vector<char>>& board) {
map<char,int> m;
for (int i = ; i < ; i++){
for (int j = ; j < ; j++){
if (board[i][j] != '.'){
if (m[board[i][j]]) return false;
m[board[i][j]]++;
}
}
m.clear();
}
for (int i = ; i < ; i++){
for (int j = ; j < ; j++){
if (board[j][i] != '.'){
if (m[board[j][i]]) return false;
m[board[j][i]]++;
}
}
m.clear();
}
for (int i = ; i < ; i++){
for (int j = ; j < ; j++){
for (int r = i*; r < i*+; r++){
for (int l = j*; l < j*+; l++){
if (board[r][l] != '.'){
if (m[board[r][l]]) return false;
m[board[r][l]]++;
}
}
}
m.clear();
}
}
return true;
}
};

LeetCode 36. Valid Sudoku (C++)的更多相关文章

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

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

  2. LeetCode 36 Valid Sudoku

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

  3. Java [leetcode 36]Valid Sudoku

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

  4. 蜗牛慢慢爬 LeetCode 36.Valid Sudoku [Difficulty: Medium]

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

  5. leetCode 36.Valid Sudoku(有效的数独) 解题思路和方法

    Valid Sudoku Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku bo ...

  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验证数独

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

  8. LeetCode 36. Valid Sudoku (Medium)

    题目 Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according ...

  9. LeetCode 36 Valid Sudoku(合法的数独)

    题目链接: https://leetcode.com/problems/valid-sudoku/?tab=Description   给出一个二维数组,数组大小为数独的大小,即9*9  其中,未填入 ...

随机推荐

  1. 聊聊编程开发的数据库批量插入(sql)

    这里的批量插入,主要是支持SQL的大型存储数据库,本文以Mysql,Oracle,SqlServer,postgresql4类来说明,这大概是国内应用比较多的了.其余的应该可以按照这些去找.提到编程的 ...

  2. 完全卸载MySQL数据库,实现重装

    一.在控制面板,卸载MySQL的所有组件 控制面板——>所有控制面板项——>程序和功能,卸载所有和MySQL有关的程序 二.找到你的MysQL安装路径,看还有没有和MySQL有关的文件夹, ...

  3. Ubuntu如何挂载U盘

    1. 以root用户登陆 2. 查看当前挂载 fdisk -l 一般情况未挂载的硬盘都在最后,这里是/dev/sdb1 3.新建一个目录来挂载硬盘 挂载到MNT/usb root@h-Default- ...

  4. HTML5常用标签及特殊字符表

    *http://html5doctor.com/nav*http://html5doctor.com/article*http://html5doctor.com/section*http://htm ...

  5. 动手打造轻量web服务器(二)路由

    tomcat启动慢?自己动手打造轻量web服务器(一) 上篇讲了怎么做一个最简单的web服务器,这篇就是在上篇加上URL路由功能(什么是路由?) 首先,根据http获得请求行 val scanner ...

  6. GD32F20x系列使用问题总结

    GD单片机近几年越来越火了,既有他自身相比与ST的价格优势,也有支持国货的信仰加成.然而一个新的东西,或者说一个相对较新的东西,在使用的友好性和资料的完整性方面还有很长的路要走. 现将个人使用过程中碰 ...

  7. 1071: [SCOI2007]组队

    1071: [SCOI2007]组队 https://lydsy.com/JudgeOnline/problem.php?id=1071 分析: dp+单调性. A*(hi–minH)+B*(si–m ...

  8. 【一】H.264/MPEG-4 Part 10 White Paper 翻译之 Overview of H.264

    翻译版权所有,转载请注明出处~ xzrch@2018.09.14 ------------------------------------------------------------------- ...

  9. 「Leetcode」14. Longest Common Prefix(Java)

    分析 与其说是算法题,不如说是语言特性题. 这题要是对Java的String相关函数掌握的比较熟练,写起来的速度(各种意义上)就会很快. 大致的思路都是一致的,差不到哪里去,无非是枚举长度.值得一提的 ...

  10. arduino蜂鸣器的使用

    一:蜂鸣器的使用 控制要求:模拟救护车响声 实物连接图: 电路原理图: 控制代码: //智慧自动化2018.6.11 ;//设置控制蜂鸣器的数字IO脚 void setup() { pinMode(b ...