Re: [闲聊] 每日LeetCode

楼主: Pash97143 (四叶天下第一)   2022-11-23 18:15:10
※ 引述《Rushia (みけねこ的鼻屎)》之铭言:
: 36. Valid Sudoku
: 给你一个二维字符阵列表示一个数独,包含1~9和表示空白的.字符,一个合法数独
: 满足以下条件:
: 1.每行和每列最多出现一种数字一次
: 2.一个3x3九宫格内只会出现一种数字一次
: 3.数独可能无解(无法填满数字),但是只有满足1或2才是Invalid
: 判断给定的棋盘是否是一个合法数独
: Example:
: https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Sudoku-by-L2G-20050714.svg/250px-Sudoku-by-L2G-20050714.svg.png
: Input: 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"]]
: Output: true
可恶 就我用最基础的方法
思路就一样是用set检查每行和每列是否有重复 再检查每个 3 * 3 区块是否有重复
幸好九宫格的大小都固定所以套四层循环也没关系
作者: hahaha021225 (安安你好)   2022-11-23 18:16:00
大师
作者: pandix (面包屌)   2022-11-23 18:17:00
大师
楼主: Pash97143 (四叶天下第一)   2022-11-23 18:17:00
结果这样解速度还有赢90%左右 但内存大概50%而已
作者: medama ( )   2022-11-23 18:20:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com