389
来源:互联网 发布:钉钉 心知天气 编辑:程序博客网 时间:2024/06/06 04:39
5.5
很神奇的使用了map数组,感觉自己的路子简直是有点儿野。
map数组的定义方式为:
HashMap[][] map2 = new HashMap[2][9]; for(int i = 0;i<2;i++){ for(int j = 0;j<9;j++){ map2[i][j] = new HashMap<Character,Integer>(); } }
判断数独是不是合法, 要判断同一行,同一列,以及同一个九宫之内是不是有相同的数。
虽然AC了,但是提示我的编译是有错误的。
我也不知道错在了哪里,并不想管。
class Solution { /** * @param board: the board @return: wether the Sudoku is valid */ public boolean isValidSudoku(char[][] board) { int m = board.length; if(m != 9){ return false; } int n = board[0].length; if( n != 9){ return false; } HashMap[][] map2 = new HashMap[2][9]; for(int i = 0;i<2;i++){ for(int j = 0;j<9;j++){ map2[i][j] = new HashMap<Character,Integer>(); } } // 分成了横三竖三一共九个 for(int i = 0;i < 9;i = i+3){ for(int j = 0;j<9;j= j+3){ HashMap<Character,Integer> map = new HashMap<Character,Integer>(); for(int x = i;x<i+3;x++){ for(int y = j;y<j+3;y++){ if(board[x][y] != '.'){ if(map.containsKey(board[x][y])){ //System.out.println("错误九宫,第" + x +"行,第"+ y+"列"); return false; } else{ map.put(board[x][y],1); } if(map2[0][x].containsKey(board[x][y])){ // System.out.println("错误行,第" + x +"行,第"+ y+"列"); return false; } else{ map2[0][x].put(board[x][y],1); } if(map2[1][y].containsKey(board[x][y])){ // System.out.println("错误列,第" + x +"行,第"+ y+"列"); return false; } else{ map2[1][y].put(board[x][y],1); } } } } } } return true; }};
0 0
- 389
- rqnoj-389
- ocp-389
- win2008stdx64 389端口故障
- CF contest/389
- 389高校毕业设计选题
- BOJ 389 Bricks
- UVa 389 - Basically Speaking
- 【构造】CodeForces 389D
- Codeforces 389A (最大公约数)
- #389 Valid Sudoku
- [389]Find the Difference
- LeetCode371/104/389
- leetcode 389 python
- UVA 389 Basically Speaking
- 389 Find the Difference
- 389 find the difference
- Leetcode 389(Java)
- python基础学习总结——变量使用、数据类型
- Unity3d android 通信之数据传递
- 乳腺MG数据获取(Breast Mammography)
- R语言中使用tensorflow
- java语言复制数组的四种方法
- 389
- 要学的东西
- 从程序员到项目经理(6):程序员加油站 -- 懂电脑更要懂人脑
- 去掉标题栏和全屏的三种方法
- oracle学习笔记 检查点队列(checkpoint queue)
- 卷积神经网络实战(可视化部分)——使用keras识别猫咪
- Servlet 通过表单上传文件和获取表单数据的最简单方式
- express学习手记
- ImageNet和CNN怎样帮助医学图像的识别