博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[leetcode]Valid Sudoku
阅读量:7026 次
发布时间:2019-06-28

本文共 1804 字,大约阅读时间需要 6 分钟。

问题描写叙述:

Determine if a Sudoku is valid, according to: .

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

A partially filled sudoku which is valid.

Note:

A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated.

代码:

public class Valid_Sudoku {  //java	public boolean isValidSudoku(char[][] board) {        		int size = 9;		int [] member = new int[size];   //record if is occur; 				//valid row		for(int i = 0; i < 9; i++){						for(int k = 0; k < 9; k++)				member[k] = 0;			for(int j = 0; j < 9; j++){				if(board[i][j] == '.')					continue;				int pos = board[i][j]-'0';				if(member[pos-1] == 1)					return false;				else member[pos-1] = 1;			}		}				//valid col		for(int i = 0; i < 9; i++){			for(int k = 0; k < 9; k++)				member[k] = 0;			for(int j = 0; j < 9; j++){				if(board[j][i] == '.')					continue;				int pos = board[j][i]-'0';				if(member[pos-1] == 1)					return false;				else member[pos-1] = 1;			}		}				//valid cube		for(int ibegin = 0; ibegin < 9; ibegin = ibegin+3){			for(int jbegin = 0; jbegin < 9; jbegin = jbegin+3){				for(int k = 0; k < 9; k++)					member[k] = 0;				for(int i = ibegin; i < ibegin+3; i++){					for(int j = jbegin; j < jbegin+3; j++){						if(board[i][j] == '.')							continue;						int pos = board[i][j]-'0';						if(member[pos-1] == 1)							return false;						else member[pos-1] = 1;					}				}			}		}		return true;    }		public static void main(String [] args){		String[] boardStr = {"......5..",							 ".........",							 ".........",							 "93..2.4..",							 "..7...3..",							 ".........",							 "...34....",							 ".....3...",							 ".....52.."};		char [][] board = new char [9][9];		for(int i =0; i< boardStr.length; i++){			for(int j = 0; j

转载地址:http://kulxl.baihongyu.com/

你可能感兴趣的文章
POJ1386Play on Words(欧拉回路)
查看>>
batch normalization在测试时的问题
查看>>
Python时间和日期
查看>>
uchome中模糊搜索的实现
查看>>
五子棋AI的思路
查看>>
AtomicInteger和count++的比较
查看>>
JS删除数组条目中重复的条目
查看>>
Servlet客户请求的处理:HTTP请求报头HttpServletRequest接口应用
查看>>
pat 1014 1017 排队类问题
查看>>
常见负载均衡的优点和缺点对比(Nginx、HAProxy、LVS)
查看>>
Mac电脑C语言开发的入门帖
查看>>
洛谷P4242 树上的毒瘤
查看>>
JQ实现树形菜单点击高亮
查看>>
函数动态参数
查看>>
华为机试题 -- 明明的随机数
查看>>
一道简单的数学题
查看>>
为什么 执行typeof null时会返回字符串“object”?
查看>>
JavaScript关于闭包的理解和实例
查看>>
jquery-ui-widget
查看>>
VC Error spawning cl.exe
查看>>