-
-
Notifications
You must be signed in to change notification settings - Fork 304
[robinyoon-dev] WEEK 02 solutions #2035
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
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.
코드 내에 주석을 잘 작성해주셔서 풀이를 이해하기 쉬웠던 것 같아요!
이번 한 주도 고생 많으셨습니다~! 🦾
(+ 그리고 문제 풀이 완료 후 PR의 status를 In Review로 바꿔주시면 더 빠른 리뷰가 가능합니당)
| tempArray.push(1); | ||
| }else{ | ||
| let tempSum = 0; | ||
| tempSum = tempArray[i - 2] + tempArray[i - 1]; |
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.
이렇게 DP 테이블의 가장 최근 n개의 원소만 사용하는 경우에는 O(n) space의 DP 테이블 대신 O(1)space의 변수를 사용해서 공간 복잡도를 한 단계 최적화 할 수 있을 것 같아요~!
|
|
||
| //2. sArray와 tArray의 sort를 같게 만든다. | ||
| const sortedSArray = sArray.sort(); | ||
| const sortedTArray = tArray.sort(); |
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.
정렬을 이용해서 풀이하셨네요! 정렬을 하게 되면 시간 복잡도가 O(nlogn)이 되는데요, 카운팅을 이용하면 시간 복잡도를 약간 더 최적화 할 수 있어 이렇게도 한 번 풀어보시는 걸 추천드려요~!
| // (지금 보니 이 부분은 zeroCount === 1로 했어도 될 것 같네요...) | ||
| tempArray.push(0); | ||
| } else { | ||
| tempArray.push(totalProduct / nums[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.
문제의 without using the division operation 조건이 위배되는 부분인 것 같습니다! prefix sum을 응용해서 풀어보시는 걸 추천드려요~!
| var productExceptSelf = function (nums) { | ||
|
|
||
| const NUMS_LENGTH = nums.length; | ||
| const isZeroArray = []; //boolean |
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.
O(1) extra space를 사용하라는 follow up 조건을 위해서 isZeroArray 리스트는 제거해도 될 것 같아요~!
for 문 내에서 검사할 때는 nums[i] === 0으로 검사하면 되고, 이미 zeroCount로 전체 0 개수를 알고 있기 때문입니다!
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!