Skip to content

Conversation

obaibula
Copy link
Contributor

The previous solution did not match the video explanation.

The new solution has been adjusted to align with the video, but it uses arrays instead of maps. Here’s why:

Since Go does not have a set structure, we would typically use a map, specifically map[int]map[byte]bool. However, if the inner map is not initialized with the make function, attempting to insert values into a nil map will result in a panic. Therefore, in each iteration, we must check whether map[byte]bool is nil and create it if necessary.

This issue can be resolved by using arrays, which is why I decided to adjust the solution to use arrays instead of map[int]map[byte]bool.

The map-based solution would require three additional if statements, as shown in this submission: https://leetcode.com/problems/valid-sudoku/submissions/1421056544/.

@Ykhan799 Ykhan799 merged commit e8c3dbe into neetcode-gh:main Oct 20, 2024
@Ykhan799
Copy link
Collaborator

@obaibula Good refactoring, Thanks for your contribution 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants