Leetcode-Valid Sudoku
来源:互联网 发布:游戏秘籍输入器源码 编辑:程序博客网 时间:2024/06/07 09:50
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 cnt[10];for (int i = 0; i < 9; i++) { //每一行满足的条件memset(cnt, 0, sizeof(cnt));for (int j = 0; j < 9; j++) {if (board[i][j] != '.') {cnt[board[i][j] - '0']++;if (cnt[board[i][j] - '0']>1)return false;}}}for (int j = 0; j < 9; j++) { //每一列满足的条件memset(cnt, 0, sizeof(cnt));for (int i = 0; i < 9; i++) {if (board[i][j] != '.') {cnt[board[i][j] - '0']++;if (cnt[board[i][j] - '0']>1)return false;}}}for (int i = 0; i < 9; i += 3) //每个宫满足的条件{for (int j = 0; j < 9; j += 3){memset(cnt, 0, sizeof(cnt));for (int a = i; a < i + 3; a++){for (int b = j; b < j + 3; b++){if (board[a][b] != '.'){cnt[board[a][b] - '0']++;if (cnt[board[a][b] - '0'] > 1)return false;}}}}}return true;}};
阅读全文
0 0
- 【LeetCode】Valid Sudoku && Sudoku Solver
- [Leetcode]Sudoku Solver&&Valid Sudoku
- leetcode Valid Sudoku & Sudoku Solver
- LeetCode : Valid Sudoku
- [LeetCode]Valid Sudoku
- [leetcode] Valid Sudoku
- LeetCode-Valid Sudoku
- LeetCode Valid Sudoku
- LeetCode - Valid Sudoku
- LeetCode:Valid Sudoku
- leetcode-036:Valid Sudoku
- Leetcode: Valid Sudoku
- LeetCode题解:Valid Sudoku
- 【LeetCode】 Valid Sudoku
- Leetcode Valid Sudoku
- LeetCode | Valid Sudoku
- LeetCode Valid Sudoku
- [Leetcode] Valid Sudoku (Java)
- 堆排序
- dts list python tool
- Facebook加入直播功能,带你窥探虚拟现实世界
- 如何使用dreamweave cc给图片加热点链接?
- 通过servlet连接数据库和HTML,完成登陆注册
- Leetcode-Valid Sudoku
- 第六章项目时间管理
- 每日vim系列0713
- 前端学习(二)mac安装nvm
- 多线程之NSOperation
- linux 下安装MySQL出现问题 Access denied for user ''@'localhost' to database 'mysql'
- 使用sklearn做各种回归
- SDK测试、移动应用测试解决方案—昆山中创软件工程有限公司
- STC89C52MCU--基础知识2