当前位置:网站首页>【刷题篇】有效的数独
【刷题篇】有效的数独
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;
}
边栏推荐
- obj集合转为实体集合
- 阿掌的怀念
- Find the root of the following equation by chord cutting method, f (x) =x^3-5x^2+16x-80=0
- Boost the development of digital economy and consolidate the base of digital talents - the digital talent competition was successfully held in Kunming
- [graduation season] as a sophomore majoring in planning, I have something to say
- 事务回滚异常
- You should have your own persistence
- Flet教程之 09 NavigationRail 基础入门(教程含源码)
- 数据访问 - EntityFramework集成
- 移动办公时如何使用frp内网穿透+teamviewer方式快速连入家中内网主机
猜你喜欢
DeSci:去中心化科学是Web3.0的新趋势?
单商户 V4.4,初心未变,实力依旧!
Mistakes made when writing unit tests
ES6 deep - ES6 class class
Research and development efficiency measurement index composition and efficiency measurement methodology
Desci: is decentralized science the new trend of Web3.0?
OneForAll安装使用
Seaborn绘制11个柱状图
单商户 V4.4,初心未变,实力依旧!
ES6深入—ES6 Class 类
随机推荐
不敢买的思考
求解汉诺塔问题【修改版】
详解SQL中Groupings Sets 语句的功能和底层实现逻辑
写单元测试的时候犯的错
Seaborn draws 11 histograms
Use of RLOCK lock
The difference between abstract classes and interfaces
[vulnerability warning] cve-2022-26134 conflict Remote Code Execution Vulnerability POC verification and repair process
Flet教程之 11 Row组件在水平数组中显示其子项的控件 基础入门(教程含源码)
Accès aux données - intégration du cadre d'entité
漫画:什么是分布式事务?
Boost the development of digital economy and consolidate the base of digital talents - the digital talent competition was successfully held in Kunming
vant tabbar遮挡内容的解决方式
国泰君安网上开户安全吗
阿掌的怀念
一些認知的思考
普洛斯数据中心发布DC Brain系统,科技赋能智慧化运营管理
记一次'非常诡异'的云安全组规则问题排查过程
數據訪問 - EntityFramework集成
迁移/home分区