[Leetcode] Array--Effective Sudoku

Source: Internet
Author: User

Determine if a 9x9 sudoku is valid. Just follow the rules below to verify that the numbers you have filled are valid.

    1. 1-9the number can appear only once per line.
    2. Numbers 1-9 can appear only once in each column.
    3. The numbers 1-9 3x3 can only appear once in each palace separated by a thick solid line.

is a partially populated, valid Sudoku.

Sudoku part of the space has been filled in the number, the blank lattice with the ‘.‘ expression.

C + + (reference to the Great God's solution)

classSolution { Public:    BOOLIsvalidsudoku (vector<vector<Char> > &Board) {        if(Board.empty () | | board[0].empty ())return false; intm = Board.size (), n = board[0].size (); Vector<vector<BOOL> > Rowflag (M, vector<BOOL> (n,false)); Vector<vector<BOOL> > Colflag (M, vector<BOOL> (n,false)); Vector<vector<BOOL> > Cellflag (M, vector<BOOL> (n,false));  for(inti =0; I < m; ++i) { for(intj =0; J < N; ++j) {if(Board[i][j] >='1'&& Board[i][j] <='9') {                    intc = Board[i][j]-'1'; if(Rowflag[i][c] | | colflag[c][j] | | cellflag[3* (I/3) + J/3][C])return false; ROWFLAG[I][C]=true; COLFLAG[C][J]=true; cellflag[3* (I/3) + J/3][C] =true; }            }        }        return true; }};

[Leetcode] Array--Effective Sudoku

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.