[LeetCode] Valid Sudoku 解题报告
来源:互联网 发布:网络2017流行歌曲 编辑:程序博客网 时间:2024/06/05 06:41
Determine if a Sudoku is valid, according to: Sudoku Puzzles – The Rules.
The Sudoku board could be partially filled, where empty cells are filled with the character
'.'
.A partially filled sudoku which is valid.
» Solve this problem
[解题思路]
实现题。先检查行列,再检查小9格。
[Code]
1: bool isValidSudoku(vector<vector<char> > &board) {
2: // Start typing your C/C++ solution below
3: // DO NOT write int main() function
4: if(board.size() == 0) return false;
5: int row[9], col[9];
6: for(int i =0; i<9; i++)
7: {
8: memset(row, 0, 9*sizeof(int));
9: memset(col, 0, 9*sizeof(int));
10: for(int j =0; j<9; j++)
11: {
12: if(board[i][j] != '.')
13: {
14: if(row[board[i][j]-49] ==1)
15: return false;
16: row[board[i][j]-49]++;
17: }
18: if(board[j][i] != '.')
19: {
20: if(col[board[j][i]-49] ==1)
21: return false;
22: col[board[j][i]-49]++;
23: }
24: }
25: }
26: for(int i =0; i< 9; i+=3)
27: {
28: for(int j =0; j<9; j+=3)
29: {
30: memset(row, 0, 9*sizeof(int));
31: for(int m=0; m<3; m++)
32: {
33: for(int n =0; n<3; n++)
34: {
35: if(board[m+i][n+j] == '.')
36: continue;
37: if(row[board[m+i][n+j]-49] ==1)
38: return false;
39: row[board[m+i][n+j]-49]++;
40: }
41: }
42: }
43: }
44: return true;
45: }
0 0
- [LeetCode] Valid Sudoku 解题报告
- [leetcode] 36. Valid Sudoku 解题报告
- [Leetcode] 36. Valid Sudoku 解题报告
- [leetcode]36. Valid Sudoku@Java解题报告
- Leetcode #36. Valid Sudoku 数独游戏验证 解题报告
- 【LeetCode】Valid Sudoku解题笔记
- [LeetCode]Valid Sudoku解题记录
- LeetCode---Valid Sudoku解题分析
- [leetcode javascript解题]Valid Sudoku
- 【LeetCode】Valid Number 解题报告
- LeetCode解题报告--Valid Parentheses
- [LeetCode] Valid Parentheses 解题报告
- 【LeetCode】Valid Anagram 解题报告
- [LeetCode] Valid Parentheses 解题报告
- 【LeetCode】Valid Parentheses 解题报告
- Leetcode Valid Parentheses 解题报告
- [leetcode] 37. Sudoku Solver 解题报告
- [Leetcode] 37. Sudoku Solver 解题报告
- [LeetCode] Unique Paths II 解题报告
- python生成随机数组
- [LeetCode] Valid Parentheses 解题报告
- MSSQL Server数据的完整性
- MVP模式在android的使用
- [LeetCode] Valid Sudoku 解题报告
- [LeetCode] Validate Binary Search Tree 解题报告
- [LeetCode] Wildcard Matching, Solution
- [LeetCode] Word Search 解题报告
- [LeetCode] ZigZag Conversion 解题报告
- [LeetCode] Add Binary 解题报告
- [LeetCode] Anagrams 解题报告
- 关于 mysql中非null判断
- [LeetCode] Best Time to Buy and Sell Stock Solution