LeetCode:36. 有效的数独 标签:数组,哈希表

class Solution {
public:
    bool isValidSudoku(vector>& board) {
        int row[9][9];
        int column[9][9];
        int subboxs[3][3][9];
        // 初始化为零
        memset(row,0,sizeof(row));
        memset(column,0,sizeof(column));
        memset(subboxs,0,sizeof(subboxs));
        //遍历数独盒子,查看中间是否存在重复元素
        for (int i = 0; i < board.size();i++) {
            for (int j = 0; j < board[i].size(); j++) {
                if(board[i][j]>='1'&&board[i][j]<='9'){
                   int index = board[i][j] - '0'-1;
                   cout< 1) || (column[j][index] > 1) || (subboxs[i / 3][j / 3][index] > 1)) {
                        return false;
                   }
                }
            }
        }
        return true;
    }
};

你可能感兴趣的:(数组,哈希表,leetcode,散列表,算法)