leetcode36. Valid Sudoku
来源:互联网 发布:诺一网络水军 编辑:程序博客网 时间:2024/04/24 13:04
题目:
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.
比较简单,只需要检查细节就行了
AC解:
class Solution {public: bool isValidSudoku(vector<vector<char>>& board) { bool used[10]; //检查行 for (int i = 0; i < 9; i++) { fill(used,used + 10,false); for (int j = 0; j < 9; j++) { if (!check(used,board[i][j])) return false; } } //检查列 for (int i = 0; i < 9; i++) { fill(used,used + 10,false); for (int j = 0; j < 9; j++) if (!check(used,board[j][i])) return false; } //检查九方格 for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { fill(used,used + 10,false); for (int m = 3 * i; m < 3 * i + 3; m++) for (int n = 3 * j; n < 3 * j + 3; n++) if (!check(used,board[m][n])) return false; } return true; } bool check(bool used [],char a) { if (a == '.') return true; if (used[a - '0']) return false; used[a - '0'] = true; return true; }};
0 0
- [LeetCode36]Valid Sudoku
- LeetCode36:Valid Sudoku
- Leetcode36 Valid Sudoku
- LeetCode36. Valid Sudoku
- leetcode36.Valid Sudoku
- leetcode36:valid sudoku
- leetcode36~Valid Sudoku
- leetcode36. Valid Sudoku
- LeetCode36-Valid Sudoku
- leetcode36. Valid Sudoku
- LeetCode36——Valid Sudoku
- LeetCode36——Valid Sudoku
- Valid Sudoku
- Valid Sudoku
- Valid Sudoku
- Valid Sudoku
- Valid Sudoku
- Valid Sudoku
- Python14
- rownum 和 rowid
- mybatis配置文件
- +
- whatthef
- leetcode36. Valid Sudoku
- POJ
- PHP connects Hostinger MySQL database
- Oracle的游标使用方法 三种循环
- java多线程学习5,ThreadLocal
- 死锁产生的原因以及避免死锁的算法
- CaysnPrinter安卓平台开发包接口说明文档及打印示例程序
- 数据库入门(增删查改)
- CentOS安装Nginx