当前位置:网站首页>【刷题篇】有效的数独
【刷题篇】有效的数独
2022-07-05 15:55:00 【m0_60631323】
一、题目
OJ链接
请你判断一个 9 x 9 的数独是否有效。只需要 根据以下规则 ,验证已经填入的数字是否有效即可。
数字 1-9 在每一行只能出现一次。
数字 1-9 在每一列只能出现一次。
数字 1-9 在每一个以粗实线分隔的 3x3 宫内只能出现一次。(请参考示例图)
注意:
- 一个有效的数独(部分已被填充)不一定是可解的。
- 只需要根据以上规则,验证已经填入的数字是否有效即可。
- 空白格用 ‘.’ 表示。
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/valid-sudoku
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
二、题解
2.1思路


2.2源码
public boolean isValidSudoku(char[][] board) {
boolean[][] row=new boolean[9][10];
boolean[][] col=new boolean[9][10];
boolean[][] bucket=new boolean[9][10];
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
int bid=3*(i/3)+(j/3);
if(board[i][j]!='.'){
int num=board[i][j]-'0';
if(row[i][num]||col[j][num]||bucket[bid][num]){
return false;
}
row[i][num]=true;
col[j][num]=true;
bucket[bid][num]=true;
}
}
}
return true;
}
边栏推荐
- 10 minutes to help you get ZABBIX monitoring platform alarm pushed to nail group
- obj集合转为实体集合
- Cartoon: what is service fusing?
- list去重并统计个数
- OneForAll安装使用
- Desci: is decentralized science the new trend of Web3.0?
- 事务回滚异常
- Exception com alibaba. fastjson. JSONException: not match : - =
- 项目sql中批量update的时候参数类型设置错误
- Dataarts studio data architecture - Introduction to data standards
猜你喜欢

Today's sleep quality record 79 points

PSPNet | 语义分割及场景分析

普洛斯数据中心发布DC Brain系统,科技赋能智慧化运营管理

超分辨率技术在实时音视频领域的研究与实践

ES6深入—async 函数 与 Symbol 类型

Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL

Subclasses and superclasses of abstract classes

【刷题篇】鹅厂文化衫问题

HiEngine:可媲美本地的云原生内存数据库引擎

数据湖(十四):Spark与Iceberg整合查询操作
随机推荐
vant tabbar遮挡内容的解决方式
记一次'非常诡异'的云安全组规则问题排查过程
Background system sending verification code function
抽象类中子类与父类
Research and development efficiency measurement index composition and efficiency measurement methodology
不敢买的思考
Data access - entityframework integration
企业级备份软件Veritas NetBackup(NBU) 8.1.1服务端的安装部署
One click installation script enables rapid deployment of graylog server 4.2.10 stand-alone version
Boost the development of digital economy and consolidate the base of digital talents - the digital talent competition was successfully held in Kunming
国泰君安网上开户安全吗
The visual experience has been comprehensively upgraded, and Howell group and Intel Evo 3.0 have jointly accelerated the reform of the PC industry
Reduce the cost by 40%! Container practice of redis multi tenant cluster
"21 days proficient in typescript-3" - install and build a typescript development environment md
项目中批量update
清晰还原31年前现场,火山引擎超清修复Beyond经典演唱会
sql中查询最近一条记录
[graduation season] as a sophomore majoring in planning, I have something to say
开发中Boolean类型使用遇到的坑
践行自主可控3.0,真正开创中国人自己的开源事业