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

本文共 1855 字,大约阅读时间需要 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

转载于:https://www.cnblogs.com/gccbuaa/p/6905587.html

你可能感兴趣的文章
MIT Scheme 的基本使用
查看>>
程序员的“机械同感”
查看>>
在16aspx.com上下了一个简单商品房销售系统源码,怎么修改它的默认登录名和密码...
查看>>
c++回调函数
查看>>
linux下Rtree的安装
查看>>
【Java】 剑指offer(53-2) 0到n-1中缺失的数字
查看>>
Delphi中ListView类的用法
查看>>
bzoj3110: [Zjoi2013]K大数查询 【树套树,标记永久化】
查看>>
[原创]Java 的传值小例子
查看>>
博客第一弹—聊聊HTML的那些事
查看>>
Mysql安装方法及安装问题解决
查看>>
Java动态代理的两种实现方式:
查看>>
PHP trait
查看>>
python 多线程并发threading & 任务队列Queue
查看>>
1_fbauto
查看>>
IO体系、集合体系、多线程、jdbc
查看>>
关于时间:UTC/GMT/xST/ xDT
查看>>
[51Nod1089] 最长回文子串 V2(Manacher算法)
查看>>
Asp.Net生命周期系列六
查看>>
php引用 =& 详解
查看>>