leetcode Valid Sudoku 2.12 难度系数2
2014-01-26 12:28
381 查看
Question
The Sudoku board could be partially filled, where empty cells are filled with the character
A partially filled sudoku which is valid.
The Sudoku board could be partially filled, where empty cells are filled with the character
'.'.
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 Merge k Sorted Lists 难度系数3 3.11
- leetcode JAVA Subsets 难度系数3 3.27
- leetcode JAVA Partition List 难度系数3 3.30
- leetcode JAVA Reverse Words in a String 难度系数2-3?最新题151
- leetcode Balanced Binary Tree 1.10 难度系数1
- leetcode JAVA Substring with Concatenation of All Words 难度系数3 3.12
- leetcode JAVA Word Search 难度系数3 3.28
- leetcode Remove Duplicates from Sorted Array II 2.18 难度系数2
- leetcode Reverse Integer 2.2 难度系数2
- leetcode JAVA Combination Sum 难度系数3 3.13
- leetcode JAVA Remove Duplicates from Sorted List II 难度系数3 3.29
- leetcode JAVA Decode Ways 难度系数3 3.31
- leetcode Path Sum 1.2 难度系数1
- leetcode String to Integer (atoi) 2.3 难度系数2
- leetcode JAVA Permutations 难度系数3 3.14
- leetcode Length of Last Word 1.4 难度系数1
- leetcode Palindrome Number 2.4 难度系数2
- leetcode JAVA Unique Paths 2.14 难度系数2
- leetcode Best Time to Buy and Sell Stock 难度系数2 2.24
- leetcode JAVA Anagrams 难度系数3 3.15