Valid Sudoku


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.

bool isValidSudoku(char board[9][9]) {
    
    int i,j,a,b;
    int h[10];
    for(i=0;i<9;i++)
    {
        memset(h,0,sizeof(h));
        for(j=0;j<9;j++)
        {
            if(board[i][j]!='.')
            {
                if(h[board[i][j]-'0'])
                   return false;
                else
                   h[board[i][j]-'0']=1;
            }
        }
    }
    
    for(i=0;i<9;i++)
    {
        memset(h,0,sizeof(h));
        for(j=0;j<9;j++)
        {
            if(board[j][i]!='.')
            {
                if(h[board[j][i]-'0'])
                   return false;
                else
                   h[board[j][i]-'0']=1;
            }
        }
    }
    
    
    for(i=0;i<9;i+=3)
    {
        for(j=0;j<9;j+=3)
        {
            memset(h,0,sizeof(h));
            for(a=0;a<3;a++)
                for(b=0;b<3;b++)
                {
                    if(board[i+a][j+b]!='.')
                    {
                        if(h[board[i+a][j+b]-'0'])
                           return false;
                        else
                           h[board[i+a][j+b]-'0']=1;
                    }    
                }
        }
    }
    return true;
    
}