Skip to content

[이유진] Week3 #789

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

Merged
merged 3 commits into from
Dec 28, 2024
Merged

[이유진] Week3 #789

merged 3 commits into from
Dec 28, 2024

Conversation

Real-Reason
Copy link
Contributor

@Real-Reason Real-Reason commented Dec 26, 2024

답안 제출 문제

체크 리스트

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

@Real-Reason Real-Reason self-assigned this Dec 26, 2024
@Real-Reason Real-Reason requested a review from a team as a code owner December 26, 2024 16:02
@Real-Reason Real-Reason requested a review from minji-go December 26, 2024 16:03
Copy link
Contributor

@minji-go minji-go left a comment

Choose a reason for hiding this comment

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

안녕하세요 :) 문제 풀이 고생하셨습니다!

Java랑 다르게 List가 읽기 전용이고 MutableList가 따로 있는게 흥미로웠습니다.

return
}
for (i in startIdx..< candidates.size) {
val num = candidates[i]
Copy link
Contributor

Choose a reason for hiding this comment

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

저는 candidates를 정렬해서 if ( num > target ) 이면 for문 탐색을 중단하는 방식을 사용했는데, candidates length가 커질 경우를 생각해서 정렬도 고려해보시면 좋을 것 같아요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오! 그 조건을 하나 더 걸어주는 것도 좋겠네요~ :)
감사합니다~

val rightNum = mutableNums[mutableNums.size - 1 - idx]

leftStartProducts.add(leftStartProducts.last() * leftNum)
rightStartProducts.add(index = 0, element = rightStartProducts.first() * rightNum)
Copy link
Contributor

Choose a reason for hiding this comment

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

rightStartProducts의 0번째에 삽입하는 대신 add(rightStartProducts.first() * rightNum)로 삽입하고, 결과 계산을 할 때 반대로 조회하면 성능을 조금 더 개선할 수 있을 거 같아요 :)

혹은 leftStartProducts, rightStartProducts에 add() 하는 대신 result에 즉시 production을 하는 방법도 고려해보시면 좋을 거 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

list 의 0 번째 index 에 추가하는 것보다 add() 를 하는 것이 성능이 더 좋은건가요~?

result 에 즉시 production 을 하기 위해서는 누적된 곱셈값을 알고 있어야 해서 매번 계산하는 것보다는 for 문을 한 번 돌면서 leftStartProducts, rightStartProducts 에 기록된 누적곱 값을 사용하는 것이 좋다고 판단했습니다 :)

val num = candidates[i]
nums.add(num)
dfs(candidates, target, i, total + num, nums, result)
nums.removeLast()
Copy link
Contributor

Choose a reason for hiding this comment

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

저는 ArrayDeque가 익숙하지 않은데, removeLast() 메소드 덕분에 가독성이 좋은거 같네요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

kotlin 에서는 java 의 Stack 대신에 ArrayDeque 를 사용하는 것을 권장하더라구요 :)
그래서 Stack.pop() 메서드를 대신하는 것이 ArrayDeque.removeLast() 입니다

Copy link
Contributor Author

@Real-Reason Real-Reason left a comment

Choose a reason for hiding this comment

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

리뷰 감사합니다~ 😄

return
}
for (i in startIdx..< candidates.size) {
val num = candidates[i]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

오! 그 조건을 하나 더 걸어주는 것도 좋겠네요~ :)
감사합니다~

val num = candidates[i]
nums.add(num)
dfs(candidates, target, i, total + num, nums, result)
nums.removeLast()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

kotlin 에서는 java 의 Stack 대신에 ArrayDeque 를 사용하는 것을 권장하더라구요 :)
그래서 Stack.pop() 메서드를 대신하는 것이 ArrayDeque.removeLast() 입니다

val rightNum = mutableNums[mutableNums.size - 1 - idx]

leftStartProducts.add(leftStartProducts.last() * leftNum)
rightStartProducts.add(index = 0, element = rightStartProducts.first() * rightNum)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

list 의 0 번째 index 에 추가하는 것보다 add() 를 하는 것이 성능이 더 좋은건가요~?

result 에 즉시 production 을 하기 위해서는 누적된 곱셈값을 알고 있어야 해서 매번 계산하는 것보다는 for 문을 한 번 돌면서 leftStartProducts, rightStartProducts 에 기록된 누적곱 값을 사용하는 것이 좋다고 판단했습니다 :)

@Real-Reason Real-Reason merged commit b7f79ad into DaleStudy:main Dec 28, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

2 participants