leetcode Valid Sudoku 2.12 难度系数2

Question

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

leetcode Valid Sudoku 2.12  难度系数2

A partially filled sudoku which is valid.

import java.util.Hashtable;
public class Solution {
  public boolean isValidSudoku(char[][] board) {
			

			for (int i = 0; i < 9; i++) {
				Hashtable<Character, Character> ht = new Hashtable<Character, Character>();
				for (int j = 0; j < 9; j++) {
					char c = board[i][j];
					if (c==‘.‘) {
						
					}else{
						if (ht.get(c)==null) {
							ht.put(c, c);
						}else {
							return false;
						}
					}
				}
			}
			

		
			for (int i = 0; i < 9; ++i) {
				Hashtable<Character, Character> ht = new Hashtable<Character, Character>();
				for (int j = 0; j < 9; ++j) {
					char c = board[j][i];
					if (c==‘.‘) {
					
					}else{
						if (ht.get(c)==null) {
							ht.put(c, c);
						}else {
							return false;
						}
					}
				}
			}

			return isSmallValid(board, 0, 0) && isSmallValid(board, 3, 0)
					&& isSmallValid(board, 6, 0) && isSmallValid(board, 0, 3)
					&& isSmallValid(board, 3, 3) && isSmallValid(board, 6, 3)
					&& isSmallValid(board, 0, 6) && isSmallValid(board, 3, 6)
					&& isSmallValid(board, 6, 6);

		}

		private boolean isSmallValid(char[][] board, int x, int y) {
			Hashtable<Character, Character> ht = new Hashtable<Character, Character>();
			for (int i = x; i < 3 + x; ++i) {
				for (int j = y; j < 3 + y; ++j) {
					char c = board[i][j];
					if (c==‘.‘) {
					
					}else{
						if (ht.get(c)==null) {
							ht.put(c, c);
						}else {
							return false;
						}
					}
				}
			}
			return true;
		}
}


leetcode Valid Sudoku 2.12 难度系数2

上一篇:Django的Context和RequestContext


下一篇:rman中如何制定删除某段时间的归档日志