Skip to content

[tedkimdev] WEEK 02 solutions#2406

Open
tedkimdev wants to merge 2 commits intoDaleStudy:mainfrom
tedkimdev:tedkimdev/week2
Open

[tedkimdev] WEEK 02 solutions#2406
tedkimdev wants to merge 2 commits intoDaleStudy:mainfrom
tedkimdev:tedkimdev/week2

Conversation

@tedkimdev
Copy link
Contributor

답안 제출 문제

작성자 체크 리스트

  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

@hyejj19 hyejj19 self-requested a review March 11, 2026 02:15

let mut arr: [i32; 2] = [1, 2];
let mut current = 0;
for n in 3..=n {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변수명이 반복되어 오해의 소지가 있는 것 같습니다!
사용되지 않으니 언더바로 처리하는건 어떨까요?

Copy link
Contributor Author

@tedkimdev tedkimdev Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그러게요. 사용안하고 있었네요. 감사합니다.

}

target := nums[k]
for left < right {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반본묵 문법이 신기하네요
옛~날에 배운걸 떠올려보면 반복문이 for문으로 통일되어 있던것 같은데 맞나요?

Copy link
Contributor Author

@tedkimdev tedkimdev Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 맞습니다. 이 경우는 while 문으로 보시면 될 것 같아요.

for left < right {
sum := nums[left] + nums[right] + target
if sum == 0 {
if left > k {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

중복제거를 key 통일 방식으로 해결하셨군요
근데 이렇게하면 중복되는 케이스들도 연산이 필수적이되어서
중복확인을 먼저수행하는 케이스보다 효율이 조금 떨어질 것 같은데
어떻게 생각하시나요?

Copy link
Contributor Author

@tedkimdev tedkimdev Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sum 계산하기 전에 key 중복 확인을 먼저하는게 효율이 좋을거 같다는 말씀이시죠?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 맞습니다

Copy link
Contributor

@hyejj19 hyejj19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗! @dohyeon2 님께서 먼저 봐주셨군요 ㅎㅎ
이번 한 주도 문제풀이 하시느라 고생 많으셨습니다! 다음주도 화이팅이에요 💫

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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오! left와 right 배열을 각각 만들어서 계산하셨군요.
left 결과가 담긴 배열에 오른쪽 누적곱을 바로 곱해주면 배열 하나로도 풀 수 있을 것 같아요! (문법이 엄청 신기하네요 ㅎㅎ)

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

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

3 participants