bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 36. Valid Sudoku

36. Valid Sudoku

Leetcode Solutions

Approach: Hash Set

  1. Initialize three lists of hash sets, one for rows, one for columns, and one for boxes, each containing 9 sets.
  2. Iterate over each cell in the Sudoku board.
  3. For each non-empty cell, calculate the index of the corresponding box.
  4. Check if the current number exists in the hash set for the current row, column, or box.
  5. If a duplicate is found, return false.
  6. If no duplicates are found, add the number to the hash sets for the current row, column, and box.
  7. After checking all cells, if no duplicates are found, return true.
UML Thumbnail

Approach: Array of Fixed Length

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...