Skip to content

Commit c4e2437

Browse files
Update and rename ValidateSudoku.cpp to medium-36-valid_sudoku.cpp
1 parent 4b09d01 commit c4e2437

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

Codes/ValidateSudoku.cpp renamed to Codes/medium-36-valid_sudoku.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
// Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:
2+
3+
// Each row must contain the digits 1-9 without repetition.
4+
// Each column must contain the digits 1-9 without repetition.
5+
// Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition.
6+
7+
// Note:
8+
9+
// A Sudoku board (partially filled) could be valid but is not necessarily solvable.
10+
// Only the filled cells need to be validated according to the mentioned rules.
11+
12+
13+
// Example 1:
14+
15+
/* Input: board =
16+
* [["5","3",".",".","7",".",".",".","."]
17+
* ,["6",".",".","1","9","5",".",".","."]
18+
* ,[".","9","8",".",".",".",".","6","."]
19+
* ,["8",".",".",".","6",".",".",".","3"]
20+
* ,["4",".",".","8",".","3",".",".","1"]
21+
* ,["7",".",".",".","2",".",".",".","6"]
22+
* ,[".","6",".",".",".",".","2","8","."]
23+
* ,[".",".",".","4","1","9",".",".","5"]
24+
* ,[".",".",".",".","8",".",".","7","9"]]
25+
*/
26+
// Output: true
27+
28+
// Example 2:
29+
30+
/* Input: board =
31+
* [["8","3",".",".","7",".",".",".","."]
32+
* ,["6",".",".","1","9","5",".",".","."]
33+
* ,[".","9","8",".",".",".",".","6","."]
34+
* ,["8",".",".",".","6",".",".",".","3"]
35+
* ,["4",".",".","8",".","3",".",".","1"]
36+
* ,["7",".",".",".","2",".",".",".","6"]
37+
* ,[".","6",".",".",".",".","2","8","."]
38+
* ,[".",".",".","4","1","9",".",".","5"]
39+
* ,[".",".",".",".","8",".",".","7","9"]]
40+
*/
41+
// Output: false
42+
// Explanation: Same as Example 1, except with the 5 in the top left corner being modified to 8. Since there are two 8's in the top left 3x3 sub-box, it is invalid.
43+
44+
145
class Solution {
246
bool validate(vector<vector<char>> &board,int direct,int op){
347
bool visited[9];

0 commit comments

Comments
 (0)