首页 > 其他分享 >Valid Sudoku

Valid Sudoku

时间:2023-10-24 10:35:48浏览次数:33  
标签:Sudoku code character length Valid board characters

study/java #neetcode Valid Sudoku


List<Integer> list=new ArrayList<>();
Set seen = new HashSet();

board[i][j] != '.' or board[i][j] != "."

In Java, you cannot use == or != to compare strings (or characters) directly like you do with primitive data types (e.g., integers). Instead, you should use the equals method to compare strings or characters for equality.

So, when comparing a character or string with '.' (a character), you should use if (board[i][j] != '.') for characters or if (!board[i][j].equals(".")) for strings.

Here's the corrected code for comparing a string:

if (!board[i][j].equals(".")) {
    // Code to handle non-empty cell
}

And for comparing a character (which is what you're doing in your original code):

if (board[i][j] != '.') {
    // Code to handle non-empty cell
}

Remember that in your original code, you were working with characters (char data type), not strings (String data type). So, using != to compare a character to a character literal (e.g., '.') is the correct way to check if a cell contains a period character.

2 D Array Length

In Java, you can get the length of a row or column in a 2D array (such as char[][] board) using the .length property. Here's how you can do it:

  1. To get the number of rows:
int numRows = board.length;
  1. To get the number of columns in a specific row (assuming all rows have the same length, which is typical for a Sudoku board):
int numColumns = board[0].length;

Keep in mind that the above code assumes that board is a properly initialized 2D array. If board is not guaranteed to have any rows or columns (i.e., it could be null), you should add appropriate checks to handle such cases to avoid null pointer exceptions.

标签:Sudoku,code,character,length,Valid,board,characters
From: https://www.cnblogs.com/HardisonDream/p/17784134.html

相关文章

  • golang validator 检验工具的使用指北
    golangvalidator包的使用指北原创阿兵云原生阿兵云原生2023-09-1009:27发表于广东看到validator咱们第一反应会想起啥?见名知意我就可以知道他是一个验证器,如果用过ginweb框架的同学,自然是用过gin里面的validator,只不过gin中使用的关键字是binding去做标识 ......
  • Flutter的Invalid use of a private type in a public API警告
    问题描述自己在写Flutter应用时发现了一个InvaliduseofaprivatetypeinapublicAPI警告。发现很多官方的例子也有这个问题。有问题的源码有问题的源码如下:classMyTabPageextendsStatefulWidget{constMyTabPage({super.key});@override_MyTabPageState......
  • gzip: stdin: invalid compressed data--format violated
    当执行解压命令,出现tar:Errorisnotrecoverable:exitingnow。tar-zxvfxxx.tar.gz错误详情如下:原因:下载的文件并不是通过gzip过滤归档,去掉-z参数即可,执行:tar-xvfxxx.tar.gz ......
  • org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
    org.apache.ibatis.binding.BindingException:Invalidboundstatement(notfound):com.tl666.comments.mapper.CommentsMapper.addRootComments2023-04-1213:40:06.160ERROR31228---[nio-8080-exec-2]o.a.c.c.C.[.[.[/].[dispatcherServlet]:Servlet.service()......
  • xxl-job执行java任务报错: unable to find valid certification path to requested tar
    1、错误:xxl-job调用https接口显示证书验证失败[错误信息:sun.security.validator.ValidatorException:PKIXpathbuildingfailed:sun.security.provider.certpath.SunCertPathBuilderException:unabletofindvalidcertificationpathtorequestedtarget]2023-10-2015......
  • Git-error: invalid path
    gitcheckoutisp原因是Win和Linux文件格式不一致,要么切换到Linux环境下操作,要么gitconfigcore.protectNTFSfalse查了下官方手册,官方原话:Ifsettotrue,donotallowcheckoutofpathsthatwouldcauseproblemswiththeNTFSfilesystem大概意思是说NTFS有个路径保......
  • 【git】git pull更新项目报错git error:invalid path
    1、报错内容error:invalidpath'xxxxxxx'原因是某分支下的文件名格式不支持,最终导致在gitclone的时候找不到这个文件路径导致的! 2、解决方法gitconfigcore.protectNTFSfalse作用是关掉NTFS下的路径保护机制,防止文件系统出错,这样就不存在找不到文件路径了......
  • 谷歌浏览器崩溃报错:STATUS_INVALID_IMAGE_HASH
    【1】问题谷歌浏览器崩溃,Edge浏览器也无法访问任何网页 【2】解决办法(2.1)方法1:直接运行脚本修复新建文本文档,重命名为.reg修改其内容为:WindowsRegistryEditorVersion5.00[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome]"RendererCodeIntegrityEnabled"=......
  • fastjson JSONValidator 的使用记录
    在api的对接过程中,对方api总是会返回一些意想不到的格式回来,虽然你们已经约定好了使用json的方式返回!! 在调用一个api接口的时候结果就像薛定谔的猫是一个不确定的形态. 按照我之前的操作逻辑1判断结果空if(StringUtils.isEmpty(result)){return"结果空";}2......
  • ant design的form的validate需要注意的点
    title:antdesign的form的validate需要注意的点date:2023-10-16author:KazooTTTtags:-antdesignpublished:trueantdesign的form的validate需要注意的点<Form.Item name="confirm" label="ConfirmPassword" dependencies={['password']}......