当前位置:网站首页>[brush questions] effective Sudoku
[brush questions] effective Sudoku
2022-07-05 16:40:00 【m0_ sixty million six hundred and thirty-one thousand three hun】
One 、 subject
OJ link
Please judge a 9 x 9 Is the Sudoku effective . It only needs According to the following rules , Verify that the numbers you have filled are valid .
Numbers 1-9 Only once in a row .
Numbers 1-9 It can only appear once in each column .
Numbers 1-9 Separated by thick solid lines in each 3x3 Only once in the palace .( Please refer to the example figure )
Be careful :
- An effective Sudoku ( Part has been filled in ) Not necessarily solvable .
- Just follow the above rules , Verify that the numbers you have filled are valid .
- Blank space ‘.’ Express .
source : Power button (LeetCode)
link :https://leetcode.cn/problems/valid-sudoku
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Two 、 Answer key
2.1 Ideas
2.2 Source code
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;
}
边栏推荐
- "21 days proficient in typescript-3" - install and build a typescript development environment md
- 国泰君安网上开户安全吗
- 今日睡眠质量记录79分
- Binary tree related OJ problems
- Is it safe for Guotai Junan to open an account online
- 漫画:什么是分布式事务?
- Quelques réflexions cognitives
- Mongodb getting started Tutorial Part 04 mongodb client
- 【刷题篇】鹅厂文化衫问题
- ES6深入—async 函数 与 Symbol 类型
猜你喜欢
随机推荐
Single merchant v4.4 has the same original intention and strength!
公司自用的国产API管理神器
一键安装脚本实现快速部署GrayLog Server 4.2.10单机版
Oneforall installation and use
Enter a command with the keyboard
HiEngine:可媲美本地的云原生内存数据库引擎
The database of the server is not connected to 200310060 "unknown error" [the service is up, the firewall is off, the port is on, and the netlent port is not connected]
阿掌的怀念
国泰君安网上开户安全吗
【学术相关】多位博士毕业去了三四流高校,目前惨不忍睹……
Accès aux données - intégration du cadre d'entité
Research and development efficiency measurement index composition and efficiency measurement methodology
Win11 prompt: what if the software cannot be downloaded safely? Win11 cannot download software safely
践行自主可控3.0,真正开创中国人自己的开源事业
漫画:什么是蓝绿部署?
ES6 drill down - Async functions and symbol types
How to uninstall MySQL cleanly
Cartoon: what is MapReduce?
Global Data Center released DC brain system, enabling intelligent operation and management through science and technology
Win11提示无法安全下载软件怎么办?Win11无法安全下载软件