Open
Conversation
dongrri22
reviewed
Apr 6, 2023
| @@ -0,0 +1,47 @@ | |||
| // 인접 행렬을 1차원 배열로 만듦 -> 통과 | |||
Contributor
There was a problem hiding this comment.
메모리 초과, 시간 초과를 1차원 배열을 이용해 해결할 수 있네요
dongrri22
reviewed
Apr 6, 2023
| let visited = new Array(n); | ||
| for (let i = 0; i < n; i++) visited[i] = new Array(n).fill(false); | ||
|
|
||
| const dfs = (i, j, height) => { |
Contributor
There was a problem hiding this comment.
이렇게 각 방향마다 dfs 함수를 호출하는 방법도 있네요
dongrri22
reviewed
Apr 6, 2023
| visited[0] = true; | ||
|
|
||
| const adjacent = new Array(n + 1); | ||
| // adjacent 배열을 new Array(n + 1).fill(new Array(n + 1).fill(0))로 했을 경우 왜 밑에 forEach문이 제대로 동작하지 않는가? |
Contributor
There was a problem hiding this comment.
반복문 안에서 자체적으로 new Array( ) 생성자를 반복해주면 어떨까요?
dongrri22
reviewed
Apr 6, 2023
|
|
||
| const adjacent = new Array(n + 1); | ||
| // adjacent 배열을 new Array(n + 1).fill(new Array(n + 1).fill(0))로 했을 경우 왜 밑에 forEach문이 제대로 동작하지 않는가? | ||
| // 한번에 여러 인덱스가 같이 바뀌어버리는 이유? |
Contributor
There was a problem hiding this comment.
fill 메서드가 값을 복사해 할당해 주는데, fill의 매개변수로 객체가 전달되어 동일한 주소가 전달되는게 아닐까요?
sena-22
approved these changes
May 5, 2023
| } | ||
| if (cabbageField[nowI]?.[nowJ + 1] && !visited[nowI]?.[nowJ + 1]) { | ||
| visited[nowI][nowJ + 1] = true; | ||
| queue.push([nowI, nowJ + 1]); |
Contributor
There was a problem hiding this comment.
이 부분은 반복문을 사용하면 더 간결할 것 같아요
| 3. queue 생성 (처음에 V 넣고 시작) | ||
| 4. queue에 있는 노드를 빼고 해당 노드의 (방문하지 않은) 인접 노드들을 queue에 넣는다. 이때 queue에서 빠지면 | ||
| visited 배열에 체크하고, 정답에 추가한다. | ||
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.