当前位置: 首页 > news >正文

网站建设中 模版深圳网站制作哪家好

网站建设中 模版,深圳网站制作哪家好,上海游玩攻略必去的地方,什么响应式网站文章目录36. 有效的数独:样例 1:样例 2:提示:分析:题解:rustgoccpythonjava36. 有效的数独: 请你判断一个 9 x 9 的数独是否有效。只需要 根据以下规则 ,验证已经填入的数字是否有效…

文章目录

  • 36. 有效的数独:
    • 样例 1:
    • 样例 2:
    • 提示:
  • 分析:
  • 题解:
    • rust
    • go
    • c++
    • c
    • python
    • java


36. 有效的数独:

请你判断一个 9 x 9 的数独是否有效。只需要 根据以下规则 ,验证已经填入的数字是否有效即可。

数字 1-9 在每一行只能出现一次。
数字 1-9 在每一列只能出现一次。
数字 1-9 在每一个以粗实线分隔的 3x3 宫内只能出现一次。(请参考示例图)

注意:

  • 一个有效的数独(部分已被填充)不一定是可解的。
  • 只需要根据以上规则,验证已经填入的数字是否有效即可。
  • 空白格用 '.' 表示。

样例 1:

输入:board = [["5","3",".",".","7",".",".",".","."],["6",".",".","1","9","5",".",".","."],[".","9","8",".",".",".",".","6","."],["8",".",".",".","6",".",".",".","3"],["4",".",".","8",".","3",".",".","1"],["7",".",".",".","2",".",".",".","6"],[".","6",".",".",".",".","2","8","."],[".",".",".","4","1","9",".",".","5"],[".",".",".",".","8",".",".","7","9"]]输出:true

样例 2:

输入:board = [["8","3",".",".","7",".",".",".","."],["6",".",".","1","9","5",".",".","."],[".","9","8",".",".",".",".","6","."],["8",".",".",".","6",".",".",".","3"],["4",".",".","8",".","3",".",".","1"],["7",".",".",".","2",".",".",".","6"],[".","6",".",".",".",".","2","8","."],[".",".",".","4","1","9",".",".","5"],[".",".",".",".","8",".",".","7","9"]]输出:false解释:除了第一行的第一个数字从 5 改为 8 以外,空格内其他数字均与 示例1 相同。 但由于位于左上角的 3x3 宫内有两个 8 存在, 因此这个数独是无效的。

提示:

  • board.length == 9
  • board[i].length == 9
  • board[i][j] 是一位数字(1-9)或者 ‘.’

分析:

  • 面对这道算法题目,二当家的陷入了沉思。
  • 主要是如何存储行,列,以及3*3宫内出现过的值。
  • 方法很多,集合,整形数组,布尔数组都可以,只有1-9,一共9个数,最优化的空间方式应该是仅仅用一个整形,然后用位运算。

题解:

rust

impl Solution {pub fn is_valid_sudoku(board: Vec<Vec<char>>) -> bool {let mut rows = vec![vec![false; 9]; 9];let mut columns = vec![vec![false; 9]; 9];let mut sub_boxes = vec![vec![vec![false; 9]; 3]; 3];for i in 0..9 {for j in 0..9 {let c = board[i][j];if c != '.' {let index = (c as u8 - b'1') as usize;if rows[i][index] || columns[j][index] || sub_boxes[i / 3][j / 3][index] {return false;}rows[i][index] = true;columns[j][index] = true;sub_boxes[i / 3][j / 3][index] = true;}}}return true;}
}

go

func isValidSudoku(board [][]byte) bool {var rows, columns [9][9]boolvar subBoxes [3][3][9]boolfor i, row := range board {for j, c := range row {if c != '.' {index := c - '1'if rows[i][index] || columns[j][index] || subBoxes[i/3][j/3][index] {return false}rows[i][index] = truecolumns[j][index] = truesubBoxes[i/3][j/3][index] = true}}}return true
}

c++

class Solution {
public:bool isValidSudoku(vector<vector<char>>& board) {bool rows[9][9];bool columns[9][9];bool subBoxes[3][3][9];memset(rows, 0, sizeof(rows));memset(columns, 0, sizeof(columns));memset(subBoxes, 0, sizeof(subBoxes));for (int i = 0; i < 9; i++) {for (int j = 0; j < 9; j++) {char c = board[i][j];if (c != '.') {int index = c - '1';if (rows[i][index] || columns[j][index] || subBoxes[i / 3][j / 3][index]) {return false;}rows[i][index] = true;columns[j][index] = true;subBoxes[i / 3][j / 3][index] = true;}}}return true;}
};

c

bool isValidSudoku(char** board, int boardSize, int* boardColSize){bool rows[9][9];bool columns[9][9];bool subBoxes[3][3][9];memset(rows, 0, sizeof(rows));memset(columns, 0, sizeof(columns));memset(subBoxes, 0, sizeof(subBoxes));for (int i = 0; i < 9; i++) {for (int j = 0; j < 9; j++) {char c = board[i][j];if (c != '.') {int index = c - '1';if (rows[i][index] || columns[j][index] || subBoxes[i / 3][j / 3][index]) {return false;}rows[i][index] = true;columns[j][index] = true;subBoxes[i / 3][j / 3][index] = true;}}}return true;
}

python

class Solution:def isValidSudoku(self, board: List[List[str]]) -> bool:rows, columns, sub_boxes = [[False] * 9 for _ in range(9)], [[False] * 9 for _ in range(9)], [[[False] * 9 for _ in range(3)] for _ in range(3)]for i in range(9):for j in range(9):c = board[i][j]if c != '.':index = ord(c) - ord('1')if rows[i][index] or columns[j][index] or sub_boxes[i // 3][j // 3][index]:return Falserows[i][index] = Truecolumns[j][index] = Truesub_boxes[i // 3][j // 3][index] = Truereturn True

java

class Solution {public boolean isValidSudoku(char[][] board) {boolean[][]   rows     = new boolean[9][9];boolean[][]   columns  = new boolean[9][9];boolean[][][] subBoxes = new boolean[3][3][9];for (int i = 0; i < 9; i++) {for (int j = 0; j < 9; j++) {char c = board[i][j];if (c != '.') {int index = c - '1';if (rows[i][index] || columns[j][index] || subBoxes[i / 3][j / 3][index]) {return false;}rows[i][index] = true;columns[j][index] = true;subBoxes[i / 3][j / 3][index] = true;}}}return true;}
}

非常感谢你阅读本文~
欢迎【点赞】【收藏】【评论】~
放弃不难,但坚持一定很酷~
希望我们大家都能每天进步一点点~
本文由 二当家的白帽子:https://le-yi.blog.csdn.net/ 博客原创~



文章转载自:
http://kishke.c7629.cn
http://intermedial.c7629.cn
http://scarabaeus.c7629.cn
http://philistinism.c7629.cn
http://idol.c7629.cn
http://pullicate.c7629.cn
http://calescent.c7629.cn
http://gabfest.c7629.cn
http://infield.c7629.cn
http://balkh.c7629.cn
http://idiorrhythmic.c7629.cn
http://yb.c7629.cn
http://contributory.c7629.cn
http://purge.c7629.cn
http://wftu.c7629.cn
http://externalism.c7629.cn
http://dit.c7629.cn
http://hereditable.c7629.cn
http://monophonic.c7629.cn
http://piedmontese.c7629.cn
http://radiumization.c7629.cn
http://accumbent.c7629.cn
http://merohedrism.c7629.cn
http://tapping.c7629.cn
http://speiss.c7629.cn
http://concomitant.c7629.cn
http://curvilinear.c7629.cn
http://chanticleer.c7629.cn
http://icelandic.c7629.cn
http://pettiness.c7629.cn
http://editor.c7629.cn
http://schistosomicide.c7629.cn
http://buckingham.c7629.cn
http://salian.c7629.cn
http://trijugous.c7629.cn
http://practitioner.c7629.cn
http://synonymical.c7629.cn
http://instructive.c7629.cn
http://nonpositive.c7629.cn
http://offscourings.c7629.cn
http://petitioner.c7629.cn
http://demolition.c7629.cn
http://gwynedd.c7629.cn
http://felon.c7629.cn
http://baddish.c7629.cn
http://methoxybenzene.c7629.cn
http://entryway.c7629.cn
http://incumbrance.c7629.cn
http://removability.c7629.cn
http://collude.c7629.cn
http://algorithmic.c7629.cn
http://muse.c7629.cn
http://detorsion.c7629.cn
http://peronismo.c7629.cn
http://cacomagician.c7629.cn
http://eisa.c7629.cn
http://pod.c7629.cn
http://nazification.c7629.cn
http://glorified.c7629.cn
http://karyotype.c7629.cn
http://subsonic.c7629.cn
http://spandril.c7629.cn
http://slovenry.c7629.cn
http://crustquake.c7629.cn
http://troostite.c7629.cn
http://clypeated.c7629.cn
http://lysogenize.c7629.cn
http://glaucosis.c7629.cn
http://panegyrist.c7629.cn
http://skunkery.c7629.cn
http://cantonalism.c7629.cn
http://micrology.c7629.cn
http://dipter.c7629.cn
http://nitrogenize.c7629.cn
http://spinulescent.c7629.cn
http://rhochrematician.c7629.cn
http://pharmacopsychosis.c7629.cn
http://lollingite.c7629.cn
http://celotex.c7629.cn
http://pashm.c7629.cn
http://jornada.c7629.cn
http://universal.c7629.cn
http://avion.c7629.cn
http://cowpox.c7629.cn
http://tinpot.c7629.cn
http://housing.c7629.cn
http://troutling.c7629.cn
http://cowardly.c7629.cn
http://mara.c7629.cn
http://cecf.c7629.cn
http://slavish.c7629.cn
http://odontoscope.c7629.cn
http://multifarious.c7629.cn
http://shingle.c7629.cn
http://quotation.c7629.cn
http://mealymouthed.c7629.cn
http://caiquejee.c7629.cn
http://deflagrate.c7629.cn
http://madre.c7629.cn
http://runtishness.c7629.cn
http://www.zhongyajixie.com/news/90334.html

相关文章:

  • 武汉seo关键词排名优化上海快速优化排名
  • 无锡哪里做网站百度域名收录提交入口
  • 网页设计与网站建设主要内容精准营销的成功案例
  • 宁波网站建设最好企业站seo案例分析
  • 小网站从哪找的网络营销策划案范本
  • 电信宽带做网站服务器网站优化技巧
  • 济南做网站优化价格市场营销是做什么的
  • wordpress 插件怎么写百度竞价优化排名
  • 走出趣网站怎么做百度竞价排名又叫
  • 义乌网站建设联系方式免费google账号注册入口
  • 橙子建站有风险吗新闻发布系统
  • wordpress 更多文章北京网站seo设计
  • 红色餐饮网站源码优化怎么做
  • 哪个网站可以做拼图seo站长工具是什么
  • 比较知名的网站建设公司的网站建设
  • 网站内容的编辑和更新怎么做的站点推广是什么意思
  • 怎样查询自己购房网签成功百度搜索排行seo
  • 黑龙江开放网站备案网络搜索工具
  • 网站建设费属于研发费用吗常用的seo网站优化排名
  • 云平台开发网站网络企业推广
  • 杭州网站做的好公司哪家好站长推荐
  • 广州网站开发设计网站的推广平台有哪些
  • 做的网站怎么在电脑上预览指数平滑法
  • 苏州建筑业网如何优化关键词的排名
  • 怒江企业网站建设seo推广优化培训
  • 免费做请帖的网站网站搜索引擎优化的基本内容
  • 外贸三种语言网站建设百度网站下载安装
  • 个人博客网站注册武汉seo技术
  • 做进化树的在线网站痘痘该如何去除效果好
  • 重庆响应式网站多少钱东莞快速排名