LEETCODE-- Valid Sudoku

来源:互联网 发布:网络机房运维方案 编辑:程序博客网 时间:2024/05/29 18:30

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.

Subscribe to see which companies asked this question

class Solution {public:    bool check(int *array, int val){        if(array[val] >= 1){            return false;        }        else{            array[val]++;            return true;        }    }    bool isValidSudoku(vector<vector<char>>& board) {     int row[10] = {0};     int column[10][10] = {0};     int subboxes[10][10] = {0};     for(int i = 0; i < 9; i++){         memset( row, 0, sizeof(row));         for(int j = 0; j < 9; j++){             if(board[i][j] != '.'){                int num = board[i][j] - '0';                if( check(row, num) && check(column[j],num) && check(subboxes[i/3*3+j/3],num)){                    //Do nothing;                }                else{                    return false;                }             }         }     }     return true;    }};
0 0
原创粉丝点击