36. Valid Sudoku / Medium / JavaScript #50
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
설명
for문 2개를 중첩해서
1행 1열, 1행 2열, 1행 3열... 순으로 돌면서
루프를 도는 동안 위의 네 가지 조건에 어긋나는 순간
false
반환중첩 루프를 모두 통과하면
true
를 반환함Time Complexity: O(1)
루프가 중단되지 않고 끝까지 실행된다고 하면
중첩된 루프를 도는 횟수는 총 9*9로 81회.
Space Complexity: O(1)
수도쿠에 사용할 수 있는 숫자가 1~9로 제한되어 있기 때문에
중복 확인을 위해 만드는 객체들도 그 사이즈가 제한됨
결국 상수의 공간 복잡도를 가짐.