Skip to content

36. Valid Sudoku / Medium / JavaScript #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

yeongrok-jeong
Copy link
Contributor

설명

for문 2개를 중첩해서
1행 1열, 1행 2열, 1행 3열... 순으로 돌면서

  1. 숫자가 있으면, 그 숫자가 유효 범위(1 <= num <= 9)에 있는지 확인하고,
  2. 해당 열에 중복된 숫자가 없는지를 객체로 관리하여 확인,
  3. 한 행의 루프가 도는 동안엔 그 행에 중복된 숫자가 없는지를 객체로 관리하여 확인,
  4. 3 x 3 sub-boxes를 0부터 9까지 순서로 이름을 붙인다고 하면, 각 area에 중복된 숫자가 없는지를 객체로 관리하여 확인함

루프를 도는 동안 위의 네 가지 조건에 어긋나는 순간 false 반환
중첩 루프를 모두 통과하면 true를 반환함

Time Complexity: O(1)

루프가 중단되지 않고 끝까지 실행된다고 하면
중첩된 루프를 도는 횟수는 총 9*9로 81회.

Space Complexity: O(1)

수도쿠에 사용할 수 있는 숫자가 1~9로 제한되어 있기 때문에
중복 확인을 위해 만드는 객체들도 그 사이즈가 제한됨
결국 상수의 공간 복잡도를 가짐.

@yeongrok-jeong yeongrok-jeong requested a review from lynn0506 May 11, 2023 16:29
@yeongrok-jeong yeongrok-jeong self-assigned this May 11, 2023
@yeongrok-jeong
Copy link
Contributor Author

셀프 리뷰 : 아주 직관적인 풀이다 ^_^

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.

1 participant