leetcode114:valid-sudoku
题目描述

The Sudoku board could be partially filled, where empty cells are filled with the character'.'.

A partially filled sudoku which is valid.
class Solution {
public:
bool isValidSudoku(vector<vector<char> > &board) {
//记录已经出现的数,如3出现,则row[3]=1
int row[10] = {0};//之所以是10,因为下标最大是9
int col[9][10] = {0};
int square[9][10] = {0};
//行遍历,两层循环即可,只要找到重复的数即返回false
for(int i=0; i<9; i++){
//由于行重复使用了,所以每次都要清空
memset(row, 0, sizeof(row));
for(int j=0; j<9; j++){
if(board[i][j] != '.'){
if(!check(row, board[i][j] - '0') ||
!check(col[j], board[i][j] - '0') ||
//九宫格的序号:i/3*3 + j/3
!check(square[i/3*3 + j/3], board[i][j] - '0')
)
return false;
}
}
}
return true;
}
bool check(int a[], int v){
//如果每行或每列或每个九宫格出现了重复的数,那么返回false
if(a[v] == 1) return false;
a[v] = 1;
return true;
}
};
leetcode114:valid-sudoku的更多相关文章
- 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 Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...
- LeetCode:Valid Sudoku,Sudoku Solver(数独游戏)
Valid Sudoku Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku bo ...
- leetcode36. Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...
- 36. Valid Sudoku
============= Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku b ...
- 【LeetCode】36 - Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.(http://sudoku.com.au/TheRu ...
- Java [leetcode 36]Valid Sudoku
题目描述: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board cou ...
- leetcode@ [36/37] Valid Sudoku / Sudoku Solver
https://leetcode.com/problems/valid-sudoku/ Determine if a Sudoku is valid, according to: Sudoku Puz ...
- [Leetcode][Python]36: Valid Sudoku
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 36: Valid Sudokuhttps://oj.leetcode.com ...
随机推荐
- 使用 PL/SQL Developer 导入 .sql 文件
操作系统:Windows 10 x64 PL/SQL Developer Version 12.0.7.1837 (64 bit) 01.226959 第一节:下载 Oracle Database X ...
- 【题解】SP1812 【LCS2 - Longest Common Substring II 】
\(\text{Suffix Tree:}\)我来啦我来啦 \(\text{Solution:}\) 题目要求求好几个串串的\(\text{LCS.}\) 由于串串的数量并不多,所以我们把它们塞到一个 ...
- Ubuntu18.04下Git安装及使用
Ubuntu 18.04 git安装配置及基本使用 git Ubuntu 准备 对Ubuntu相关资源升级 1. linux资源升级 sudo apt-get update 2. linux软件升级 ...
- 搭建zabbix+grafana监控
编写一件安装脚本 #!/bin/sh echo "\033[32;1m脚本作者:fage\033[0m" #sleep 10 zabbix_version=4.0.2 zabbix ...
- Python 导入模块的两种方法:import xxx 和from...import xxx
import 方式导入模块 import tool.getsum.add # 导入模块,优先会从启动文件的当前目录开始寻找 # 如果找到,就使用 # 如果找不到,会在系统模块存放目录去 tool.ge ...
- SDN实验 3: Mininet 实验——测量路径的损耗率
验 3:Mininet 实验--测量路径的损耗率 一.实验目的 在实验 2 的基础上进一步熟悉 Mininet 自定义拓扑脚本,以及与损耗率相关的设定:初步了解 Mininet 安装时自带的 POX ...
- 【linux-centos】安装ifstat!
1.卸载原装ifstat find / -name *ifstat* 把/usr/sbin/ifstat.ifstat的man目录的.gz文件删除 2.下载安装 wget http://gael.ro ...
- ucore操作系统学习笔记(二) ucore lab2物理内存管理分析
一.lab2物理内存管理介绍 操作系统的一个主要职责是管理硬件资源,并向应用程序提供具有良好抽象的接口来使用这些资源. 而内存作为重要的计算机硬件资源,也必然需要被操作系统统一的管理.最初没有操作系统 ...
- go内建方法 make方法
package main import "fmt" func main() { // make函数 makeSlice() // 创建切片 makeMap() // 创建集合 ma ...
- 在windows2003上安装itunes
本人使用windows server 2003系统 安装itunes时提示 AppleMobileDeviceSupport 只能按照在xp系统上或以上版本,你可以忽略这个错误.继续安装吧. 这样除了 ...