Open
Conversation
dohyeon2
reviewed
Mar 12, 2026
|
|
||
| let mut arr: [i32; 2] = [1, 2]; | ||
| let mut current = 0; | ||
| for n in 3..=n { |
Contributor
There was a problem hiding this comment.
변수명이 반복되어 오해의 소지가 있는 것 같습니다!
사용되지 않으니 언더바로 처리하는건 어떨까요?
Contributor
Author
There was a problem hiding this comment.
그러게요. 사용안하고 있었네요. 감사합니다.
| } | ||
|
|
||
| target := nums[k] | ||
| for left < right { |
Contributor
There was a problem hiding this comment.
반본묵 문법이 신기하네요
옛~날에 배운걸 떠올려보면 반복문이 for문으로 통일되어 있던것 같은데 맞나요?
Contributor
Author
There was a problem hiding this comment.
네 맞습니다. 이 경우는 while 문으로 보시면 될 것 같아요.
| for left < right { | ||
| sum := nums[left] + nums[right] + target | ||
| if sum == 0 { | ||
| if left > k { |
Contributor
There was a problem hiding this comment.
중복제거를 key 통일 방식으로 해결하셨군요
근데 이렇게하면 중복되는 케이스들도 연산이 필수적이되어서
중복확인을 먼저수행하는 케이스보다 효율이 조금 떨어질 것 같은데
어떻게 생각하시나요?
Contributor
Author
There was a problem hiding this comment.
sum 계산하기 전에 key 중복 확인을 먼저하는게 효율이 좋을거 같다는 말씀이시죠?
hyejj19
approved these changes
Mar 13, 2026
Comment on lines
+3
to
+24
| func productExceptSelf(nums []int) []int { | ||
| result := make([]int, 0) | ||
|
|
||
| left := make([]int, len(nums)) | ||
| left[0] = 1 | ||
|
|
||
| right := make([]int, len(nums)) | ||
| right[len(nums)-1] = 1 | ||
|
|
||
| for i := 1; i < len(nums); i++ { | ||
| left[i] = nums[i-1] * left[i-1] | ||
| } | ||
|
|
||
| for i := len(nums) - 2; i >= 0; i-- { | ||
| right[i] = nums[i+1] * right[i+1] | ||
| } | ||
|
|
||
| for i := 0; i < len(nums); i++ { | ||
| result = append(result, left[i]*right[i]) | ||
| } | ||
| return result | ||
| } |
Contributor
There was a problem hiding this comment.
오! left와 right 배열을 각각 만들어서 계산하셨군요.
left 결과가 담긴 배열에 오른쪽 누적곱을 바로 곱해주면 배열 하나로도 풀 수 있을 것 같아요! (문법이 엄청 신기하네요 ㅎㅎ)
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.
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!