public class Solution { public bool IsValidSudoku(char[,] board) { for (int i = 0; i < 9; i++) { var dic = new Dictionary<char, int>(); for (int j = 0; j < 9; j++) { var num = board[i, j]; if (num == '.') { continue; } if (dic.ContainsKey(num)) { return false; } else { dic.Add(num, 1); } } dic.Clear(); } for (int j = 0; j < 9; j++) { var dic = new Dictionary<char, int>(); for (int i = 0; i < 9; i++) { var num = board[i, j]; if (num == '.') { continue; } if (dic.ContainsKey(num)) { return false; } else { dic.Add(num, 1); } } dic.Clear(); } for (int a = 0; a < 3; a++) { for (int b = 0; b < 3; b++) { var dic = new Dictionary<char, int>(); for (int i = 3 * a; i < 3 * (a + 1); i++) { for (int j = 3 * b; j < 3 * (b + 1); j++) { //Console.Write(i + "," + j + " "); var num = board[i, j]; if (num == '.') { continue; } if (dic.ContainsKey(num)) { return false; } else { dic.Add(num, 1); } } } dic.Clear(); //Console.WriteLine(); } } return true; } }