Leetcode:Valid Sudoku

基于物联网技术智慧园林绿化养护管理信息平台 近几年来,随着经济不断的发展,城市面积不断的扩大,城市管理中的园林绿化工作也在这种趋势下不断的发生着深刻改变。管养企业是否按制定的管养计划严格执行?绿化事件整改是否及时到位?绿地面积是否在稳步增长?管养的效果如何?如何客观评价管养企业的管养工作?这些都是我们各级管理者需要面对的问题。   智慧园林绿化养护管理信息平台的开发思路以“考核”为核心,整个信息平台体现出“新、快、高、全、享”五个特点。   智慧园林绿化养护管理信息平台的整个开发理念为:依托五大技术手段(全球卫星定位系统技术、地理信... 阅读详情

Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.

The Sudoku board could be partially filled, where empty cells are filled with the character '.'.

翻译一下就是

给你个数独的二维数组,有的地方数字是有的,有的地方没有数字,没有数字的地方就是“。”来代替

然后每行、每列、每个九宫格内的数字不要重复

很简单的一题

但是我的办法就很蠢了,先找每行和每列是不是重复了,然后再单独找九宫格里面是不是重复了

我用的hashset来处理的

public class Solution {
    public boolean isValidSudoku(char[][] board) {
        for(int i=0;i<9;i++){
            Set<Character> hash1=new HashSet<Character>();
            Set<Character> hash2=new HashSet<Character>();
            for(int j=0;j<9;j++){
                if(board[i][j]!='.'){
                    if(!hash1.add(board[i][j]))
                    return false;
                }
                   if(board[j][i]!='.'){
                    if(!hash2.add(board[j][i]))
                    return false;
                }
            }
        }
 
        

       for(int k=0;k<9;k++){
            int row=k/3;
            int col=k%3;
             Set<Character> hash3=new HashSet<Character>();
            for(int i=row*3;i<row*3+3;i++){
                for(int j=3*col;j<3*col+3;j++){
                    if(board[i][j]!='.'){
                        if(!hash3.add(board[i][j]))
                            return false;
                        }
                    }
                }
            }
        return true;
    }
}


然后还有一种很奇妙的算法,只用了两重循环就解决了

思想就是,用三个9*9的二维数组默认全是0,分别来存每行、每列、每个九宫格的值,重点是算的时候很妙!

就是算出给的二维数组[i][j]位置的值int num=board[i][j]-'0'-1,然后再自己的9*9数组中把这个num位置置为1

比如第i行,那就是[i][num]=1,第j列就是[num][j]=1,重点就是第k个九宫格怎么表示,k = i / 3 * 3 + j / 3,于是[k][num]=1

最后再到num出现时,如果那一行或者那一列或者那个九宫格有过了,那么此时(used1[i][num]==1 )|| (used2[j][num]==1) ||(used3[k][num]==1)

好了,我描述的也不清楚,直接上代码吧

public class Solution {
    public boolean isValidSudoku(char[][] board) {
        int[][] used1 = new int[9][9];
        int[][] used2 = new int[9][9];
        int[][] used3 = new int[9][9];

        for(int i = 0; i < 9; ++ i)
            for(int j = 0; j < 9; ++ j)
                if(board[i][j] != '.')
                {
                    int num = board[i][j] - '0' - 1, k = i / 3 * 3 + j / 3;
                    if((used1[i][num]==1 )|| (used2[j][num]==1) ||(used3[k][num]==1))
                        return false;
                    used1[i][num] = used2[j][num] = used3[k][num] = 1;
                }

        return true;
    }
}


【机器人技术基础】MATLAB Robotics Toolbox PUMA560 运动学正逆解 机器人技术基础实验2报告 1. 实验目的和要求 2. 实验手段 2.1 实验原理 2.2 函数详解 3. 实验主要内容 4. 实验结果和分析 4.1 正运动学求解 例1 例2 4.2 逆运动学求解 例1 例2 1. 实验目的和要求 掌握常见形式的机器人的D-H坐标系建立方法、运动学建模; 正逆运动学分析与求解; 使用Robotics Toolbox对直角坐标机器人、圆柱坐标机器人、球坐标机器人、PUMA560其中之一建立运动学模型,正逆求解和仿真。 2. 实验手段 2.1 阅读详情

相关推荐

在PLC中将十六进制数据转换为浮点数(通常遵循IEEE 754标准)需要理解数据存储格式,并按以下步骤操作:

通过以上步骤,您可以在PLC中实现十六进制到浮点数的转换。T DBD20 // 将数据传送到浮点数变量(如DB1.DBD20)指数位(8位):实际指数 = 存储值 - 127(偏移量)。:必须确认PLC的存储顺序(大端或小端),否则结果错误。将两个16位寄存器合并为32位数据,需注意。尾数位(23位):隐含前导1,实际值为。:确保32位数据在寄存器中连续且对齐。符号位(1位):0表示正,1表示负。:高位寄存器在前(如西门子PLC)。:低位寄存器在前(如三菱FX系列)。,误差因截断导致)。

K11mvp的博客 4419

Leetcode1-100: 36. Valid Sudoku

Leetcode1-100: 36. Valid Sudoku问题描述解题思路implement 1implement 2代码实现implement 1 HashSet法implement 2 Brute Force法 问题描述 题目要求: 输入一个代表数独的字符型二维数组,里面元素是’.'说明没有填上,判断这个数组代表的数独是否是合法状态。 解题思路 implement 1 使用一个字符型hashSet,每次遇到一个非`'.'`元素c就存储一个字符串格式为: C + in Line + lineNo.

Y123iwantit的博客 231

DETR系列文章之–Co-DETR

Co-DETR,并行训练多个辅助头,以一对多的标签分配方式进行监督从辅助头中提取正样本坐标,为解码器中的正样本的训练效率进行额外的定制化正样本query.一对一标签分配:每个GT框分配给一个特定的query(DETR),较少的正query导致低效训练,从编码器生成的潜在表示和解码器中的注意力学习分析这一问题。一对多标签分配:每个GT框分配给检测器输出的多个proposal/anchor,依赖NMS或者anchor生成(ATSS,RetinaNet,FCOS,PAA)。

weixin_43731232的博客 2116

LeetCode题解:Valid Sudoku

Valid Sudoku Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A

Magi Su的技术回收站 3028

基于PLC1200与CB1241的RS485从站Modbus Rtu通信实战指南

本文提供了一份详细的西门子S7-1200 PLC与CB1241 RS485通讯板实现Modbus RTU从站通信的实战指南。内容涵盖从硬件接线、博途软件组态、关键参数设置到程序调试与测试的全过程,重点解析了Modbus_Slave指令配置与数据块映射,帮助工程师快速掌握工业自动化系统中的数据采集与设备接入技术。

Apple的专栏 796

光学设计进阶:Zemax中的坐标断点与离轴系统优化

本文深入解析了Zemax中坐标断点的核心原理与实战应用,它是实现离轴光学系统设计的关键。文章通过比喻和实例,详细阐述了如何利用坐标断点作为“方向盘”来精确控制光学元件的偏心和倾斜,实现“前断后接”的局部坐标系变换,从而构建并优化无中心遮拦的离轴反射系统,避免光线失控。

3a9bq4r8t2y的博客 527

Leetcode: Valid Sudoku

Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A partially filled sudo

ZkvIA的博客 1万+

# 执行 DISM 命令时出错 87 未在此上下文中识别出 restorehealth 选项。解决方法

# 执行 DISM 命令时出错 87 未在此上下文中识别出 restorehealth 选项。解决方法

段子手168的博客 1万+

LeetCode:Valid Sudoku与Sudoku Solver

Valid Sudoku1、题目: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’. Note: A

zems 418

深入解析CAN2.0A与CAN2.0B协议:帧格式与通信机制对比

本文深入对比了CAN2.0A与CAN2.0B协议的核心差异,重点解析了11位标准帧与29位扩展帧的帧格式、标识符长度及通信机制。文章阐述了CAN2.0B向下兼容的特性,并探讨了在汽车电子、工业控制等复杂网络中,如何根据项目需求、兼容性及实时性要求,在标准帧与扩展帧之间做出合理选择。

weixin_29163797的博客 395

关于瑞芯微SDK中buildroot的架构分析、配置细节、以及一些使用步骤

摘要:瑞芯微SDK基于Buildroot框架,针对RK3568等芯片提供定制化开发环境。核心目录包括buildroot(配置与编译框架)、kernel(定制内核)和u-boot(引导程序)。开发流程为:1)加载芯片默认配置;2)通过menuconfig定制系统(架构、内核、软件包等);3)可选修改内核配置。关键硬件适配需修改设备树(dts)和分区表(parameter.txt),系统行为通过启动脚本(S90network)调整。最终执行make编译生成可烧录固件。该框架通过配置文件驱动,实现从工具链构建到固

Hyjks的博客 1199

leetcode 36: Valid Sudoku

Total Accepted: 24574 Total Submissions: 90344 Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells

西施豆腐渣 2877

[LeetCode] 128: Valid Sudoku

[Problem]Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A partially fill

1.02^365的成长裂变 3642

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

leetcode:Valid Sudoku and Sudoku Solver

Question 1(Valid Sudoku): Determine if a Sudoku is valid, according to:Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character'.'. ...

weixin_34379433的博客 144

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

leetcode 36:Valid Sudoku

题目: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A partia

onlyou2030的博客 433

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

LeetCode: Valid Sudoku

Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A partially fille

514

《leetCode》:Valid Sudoku

http://sudoku.com.au/TheRules.aspx/* 思路:由于只是要我们检查一个Sudoku是否有效。并不是要我们求一个sudoku, 因此我们只需要按照sudoku的定义来检查即可。 sudoku的要求如下: 1、Each row must have the numbers 1-9 occuring just once. 2、Each column must have t

wojiushimogui的博客 655

LeetCode:Valid Sudoku

问题描述: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A part

前端产品工程师 331

leetcode笔记:Valid Sudoku

关于Sudoku矩阵的性质,可以简单概括为:对于矩阵中每一行、每一列以及每个`3×3`的九宫格区域是否存在唯一的`0~9`排列组合,如果存在相同的元素,则该Sudoku矩阵不合法。这道题比较简单,就是遍历Sudoku矩阵的所有元素,检查各元素是否满足Sudoku的性质。

liyuefeilong的专栏 2107

leetcode:Valid Sudoku

Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A partially f

u011235543的博客 261

LeetCode: sudoku solver and valid sudoku

problem: valid sudoku Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'.

denisewu的专栏 409

LeetCode[Hash Table]: Valid Sudoku

Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A partially filled su

chfe910的专栏 1613

LeetCode36:Valid Sudoku

Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A partially fille

960

LeetCode: 36. Valid Sudoku

LeetCode: 36. Valid Sudoku Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: 1. Each row must contain the digits 1-9 without repet...

Wisimer 246

LeetCode : Valid Sudoku [java]

Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A partially fille

蓝色街灯 的博客 326
上一篇: LeetCode:Happy Number
下一篇: 我来到上海
「已注销」
博客等级 码龄11年 4粉丝 16原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值