Judging whether Sudoku is legal (Lintcode)

Source: Internet
Author: User

Judging whether Sudoku is legalPlease determine if a Sudoku is valid.

The Sudoku may only be populated with partial numbers, where missing numbers are . represented.

Sample Example

The following is an example of a legal sudoku.

Note

A valid Sudoku (partial padding only) is not necessarily solvable. We just need to make the padding space valid.

Description

What's that 数独 ?

    • Http://sudoku.com.au/TheRules.aspx
    • Http://baike.baidu.com/subview/961/10842669.htm

The idea of a time-out in the first place would be to have a space for a moment. The following code appears:

After a thought, should not time out to put. But this code is actually a lot simpler.

Total time: 1005 ms

1 classSolution {2     /**3       * @paramboard:the Board4         @return: Wether the Sudoku is valid5       */6      Public BooleanIsvalidsudoku (Char[] board) {7         intR[][] =New int[9] [9];8         intL[][] =New int[9] [9];9         intA[][][] =New int[3] [3] [9];Ten          One          for(inti=0;i<9;i++) { A              for(intj=0;j<9;j++) { -R[I][J] = 0; -L[I][J] = 0; the                 if(I < 3 && J < 3) { -                      for(intk = 0; k<9; k++) -A[i][j][k] = 0; -                 } +             } -         } +          A          for(inti=0;i<9;i++) { at              for(intj=0;j<9;j++) { -                 if(Board[i][j] = = '. ')Continue; -                 intn = board[i][j]-' 0 '; -                 if(N < 0 | | n > 9)return false; -                 if(++r[i][n-1] > 1)return false; -                 if(++l[j][n-1] > 1)return false; in                 intx = I/3; -                 inty = J/3; to                 if(++a[x][y][n-1] > 1)return false; +             } -         } the          *         return true; $     }Panax Notoginseng};
View Code

Judging whether Sudoku is legal (Lintcode)

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.