LeetCode 36. Valid Sudoku
来源:互联网 发布:2016软件评测师真题 编辑:程序博客网 时间:2024/04/30 00:21
36. Valid Sudoku
My Submissions QuestionEditorial Solution
Total Accepted: 70853 Total Submissions: 232765 Difficulty: Easy
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.
Note:
A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated.
class Solution {public: bool isValidSudoku(vector<vector<char>>& board) { int book[10]; memset(book, 0, sizeof(int)*10); //每一列 for(int i = 0; i < 9; i++) { for(int j = 0; j < 9; j++) { if(board[i][j] == '.') continue; if(book[board[i][j] - '0'] == 0) book[board[i][j] - '0'] = 1; else return false; } memset(book, 0, sizeof(int) * 10); } //每一行 for(int i = 0; i < 9; i++) { for(int j = 0; j < 9; j++) { if(board[j][i] == '.') continue; if(book[board[j][i] - '0'] == 0) book[board[j][i] - '0'] = 1; else return false; } memset(book, 0, sizeof(int) * 10); } //每个小九宫格 for(int m = 0; m <= 6; m = m + 3) { for(int i = 0; i <= 8; i++) { if(i % 3 == 0) memset(book, 0, sizeof(int) * 10); for(int j = 0; j <= 2; j++) { if(board[i][j + m] == '.') continue; if(book[board[i][j + m] - '0'] == 0) book[board[i][j + m] - '0'] = 1; else return false; } } } return true; }};
0 0
- [LeetCode]36.Valid Sudoku
- LeetCode --- 36. Valid Sudoku
- LeetCode 36.Valid Sudoku
- [Leetcode] 36. Valid Sudoku
- 【leetcode】36. Valid Sudoku
- [leetcode] 36. Valid Sudoku
- Leetcode 36. Valid Sudoku
- 36. Valid Sudoku LeetCode
- leetcode 36. Valid Sudoku
- LeetCode *** 36. Valid Sudoku
- leetcode 36. Valid Sudoku
- [LeetCode]36. Valid Sudoku
- LeetCode 36. Valid Sudoku
- leetcode-36. Valid Sudoku
- 36.[Leetcode]Valid Sudoku
- Leetcode 36.Valid Sudoku
- LeetCode-36.Valid Sudoku
- leetcode 36. Valid Sudoku
- Java字符串工具类(未测试)
- LeetCode 219. Contains Duplicate II
- java lisi乱序、排序
- LeetCode 88. Merge Sorted Array
- LeetCode 160. Intersection of Two Linked Lists
- LeetCode 36. Valid Sudoku
- java中常用的时间处理类TimeUtil
- LeetCode 112. Path Sum
- LeetCode 35. Search Insert Position
- LeetCode 107. Binary Tree Level Order Traversal II
- LeetCode 102. Binary Tree Level Order Traversal
- ftp 实现文件的上传下载以及列出文件列表Java代码(未测试)
- LeetCode 101. Symmetric Tree
- LeetCode 9. Palindrome Number