36. Valid Sudoku Medium
1/**
2 * [36] Valid Sudoku
3 *
4 * Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:
5 * <ol>
6 * Each row must contain the digits 1-9 without repetition.
7 * Each column must contain the digits 1-9 without repetition.
8 * Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition.
9 * </ol>
10 * Note:
11 *
12 * A Sudoku board (partially filled) could be valid but is not necessarily solvable.
13 * Only the filled cells need to be validated according to the mentioned rules.
14 *
15 *
16 * Example 1:
17 * <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Sudoku-by-L2G-20050714.svg/250px-Sudoku-by-L2G-20050714.svg.png" style="height:250px; width:250px" />
18 * Input: board =
19 * [["5","3",".",".","7",".",".",".","."]
20 * ,["6",".",".","1","9","5",".",".","."]
21 * ,[".","9","8",".",".",".",".","6","."]
22 * ,["8",".",".",".","6",".",".",".","3"]
23 * ,["4",".",".","8",".","3",".",".","1"]
24 * ,["7",".",".",".","2",".",".",".","6"]
25 * ,[".","6",".",".",".",".","2","8","."]
26 * ,[".",".",".","4","1","9",".",".","5"]
27 * ,[".",".",".",".","8",".",".","7","9"]]
28 * Output: true
29 *
30 * Example 2:
31 *
32 * Input: board =
33 * [["8","3",".",".","7",".",".",".","."]
34 * ,["6",".",".","1","9","5",".",".","."]
35 * ,[".","9","8",".",".",".",".","6","."]
36 * ,["8",".",".",".","6",".",".",".","3"]
37 * ,["4",".",".","8",".","3",".",".","1"]
38 * ,["7",".",".",".","2",".",".",".","6"]
39 * ,[".","6",".",".",".",".","2","8","."]
40 * ,[".",".",".","4","1","9",".",".","5"]
41 * ,[".",".",".",".","8",".",".","7","9"]]
42 * Output: false
43 * 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.
44 *
45 *
46 * Constraints:
47 *
48 * board.length == 9
49 * board[i].length == 9
50 * board[i][j] is a digit 1-9 or '.'.
51 *
52 */
53pub struct Solution {}
54
55// problem: https://leetcode.com/problems/valid-sudoku/
56// discuss: https://leetcode.com/problems/valid-sudoku/discuss/?currentPage=1&orderBy=most_votes&query=
57
58// submission codes start here
59
60impl Solution {
61 pub fn is_valid_sudoku(board: Vec<Vec<char>>) -> bool {
62 false
63 }
64}
65
66// submission codes end
67
68#[cfg(test)]
69mod tests {
70 use super::*;
71
72 #[test]
73 fn test_36() {
74 }
75}
76
Back
© 2025 bowen.ge All Rights Reserved.