码迷,mamicode.com
首页 > 其他好文 > 详细

【LeetCode 36_哈希表】Valid Sudoku

时间:2015-07-08 22:12:00      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 1 //occupyed_1检查行是否占用
 2 //occupyed_2检查列是否占用
 3 //occupyed_3检查块是否占用
 4 bool isValidSudoku(vector<vector<char>>& board)
 5 {
 6     int occupyed_1[9][9], occupyed_2[9][9], occupyed_3[9][9];
 7     for (int i = 0; i < 9; ++i) {
 8         for (int j = 0; j < 9; ++j) {
 9             occupyed_1[i][j] = 0;
10             occupyed_2[i][j] = 0;
11             occupyed_3[i][j] = 0;
12         }
13     }
14 
15     int rowSize = board.size();
16     int colSize = board[0].size();
17     for (int i = 0; i < rowSize; ++i) {
18         for (int j = 0; j < colSize; ++j) {
19             if (board[i][j] != .) {
20                 int num = board[i][j] - 0 - 1;
21                 int k = i / 3 * 3 + j / 3;
22 
23                 if (occupyed_1[i][num] || occupyed_2[j][num]
24                     || occupyed_3[k][num])
25                     return false;
26                 occupyed_1[i][num] = 1;
27                 occupyed_2[j][num] = 1;
28                 occupyed_3[k][num] = 1;
29             }
30         }
31     }
32     return true;
33 }

 

【LeetCode 36_哈希表】Valid Sudoku

标签:

原文地址:http://www.cnblogs.com/mengwang024/p/4631400.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!