当前位置:网站首页>【刷题篇】有效的数独
【刷题篇】有效的数独
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;
}
边栏推荐
- Spring Festival Limited "forget trouble in the year of the ox" gift bag waiting for you to pick it up~
- Cartoon: what is distributed transaction?
- Accès aux données - intégration du cadre d'entité
- Flet教程之 11 Row组件在水平数组中显示其子项的控件 基础入门(教程含源码)
- 10分钟帮你搞定Zabbix监控平台告警推送到钉钉群
- 超分辨率技术在实时音视频领域的研究与实践
- 【毕业季】作为一名大二计科在校生,我有话想说
- 详解SQL中Groupings Sets 语句的功能和底层实现逻辑
- Win11如何给应用换图标?Win11给应用换图标的方法
- 效果编辑器新版上线!3D渲染、加标注、设置动画,这次一个编辑器就够了
猜你喜欢
随机推荐
Win11提示无法安全下载软件怎么办?Win11无法安全下载软件
抽象类中子类与父类
Obj resolves to a set
Research and practice of super-resolution technology in the field of real-time audio and video
Is it safe for Guotai Junan to open an account online
异常com.alibaba.fastjson.JSONException: not match : - =
Flet教程之 09 NavigationRail 基础入门(教程含源码)
清晰还原31年前现场,火山引擎超清修复Beyond经典演唱会
Relationship between objects and classes
Cartoon: what is the eight queens problem?
tf.sequence_mask函数讲解案例
ES6 deep - ES6 class class
Batch update in the project
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
[js] 技巧 简化if 判空
abstract关键字和哪些关键字会发生冲突呢
研发效能度量指标构成及效能度量方法论
自己要有自己的坚持
Domestic API management artifact used by the company
[vulnerability warning] cve-2022-26134 conflict Remote Code Execution Vulnerability POC verification and repair process








