# Leetcode Oj:sudoku Solver (sudoku game)

Source: Internet
Author: User

Write a program to solve a Sudoku puzzle by filling the empty cells.

Empty cells is indicated by the character `‘.‘` .

Assume that there would be is only one unique solution.

A Sudoku Puzzle ...

... and its solution numbers marked in red.

DFS, always looking, no way to return:

`1 classSolution {2  Public:3     voidSolvesudoku (vector<vector<Char>>&Board) {4 Dosudoku (board);5     }6 7     BOOLCheckvalid (vector<vector<Char>>&board,intXinty)8     {9          for(inti =0; I <9; i++){Ten             if(i!=x) One                 if(Board[i][y] = = Board[x][y])return false; A         } -  -          for(intj =0; J <9; J + +){ the             if(J! =y) -                 if(Board[x][j] = = Board[x][y])return false; -         } -  +          for(inti = (x/3) *3; I < (x/3+1) *3; ++i) { -              for(intj = (y/3) *3; J < (y/3+1) *3; ++j) { +                 if((i!=x) | | (J! =y)) A                     if(Board[x][y] = = Board[i][j])return false; at             } -         } -         return true; -     } -  -     BOOLDosudoku (vector<vector<Char>> &Board) in     { -          for(introw =0; Row <9; ++row) { to              for(intCol =0; Col <9; ++Col) { +                 if(Board[row][col] = ='.'){ -                      for(inti =1; I <=9; ++i) { theBoard[row][col] ='0'+i; *                         if(checkvalid (board, Row, col)) { \$                             if(Dosudoku (board)) {Panax Notoginseng                                 return true; -                             } the                         }     +Board[row][col] ='.'; A                     } the                     return false; +                 } -             } \$         } \$         return true; -     } -};`

Leetcode Oj:sudoku Solver (sudoku game)

Related Keywords:

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.