-
-
Notifications
You must be signed in to change notification settings - Fork 195
[이유진] 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
[이유진] Week3 #789
Conversation
There was a problem hiding this 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] |
There was a problem hiding this comment.
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가 커질 경우를 생각해서 정렬도 고려해보시면 좋을 것 같아요!
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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을 하는 방법도 고려해보시면 좋을 거 같습니다!
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 ArrayDeque가 익숙하지 않은데, removeLast() 메소드 덕분에 가독성이 좋은거 같네요!
There was a problem hiding this comment.
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() 입니다
There was a problem hiding this 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] |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 에 기록된 누적곱 값을 사용하는 것이 좋다고 판단했습니다 :)
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.