Merged
Conversation
KwonNayeon
approved these changes
Apr 11, 2025
Comment on lines
+4
to
+13
| """ | ||
| - Algorithm | ||
| - Sort and compares with three pointers: target, left(l), right(r) | ||
| - Time Complexity: O(n^2), n = len(nums) | ||
| - sort : O(nlogn) | ||
| - nested two loops : O(n^2) | ||
| - O(nlogn + n^2) => O(n^2) | ||
| - Space Complexity: O(n^2) if result included. | ||
| - result size : result.append() called in n^2 times (nested two loops) | ||
| """ |
Contributor
There was a problem hiding this comment.
@ayosecu 님 안녕하세요! 저도 투포인터를 활용하여 문제를 풀었습니다. 개인적으로 알고리즘 문제를 풀 때 tc, sc를 생각해내는 게 항상 어려운데, 이 부분을 잘 정리해주셔서 복습하는 데 도움이 많이 됐습니다!
Contributor
There was a problem hiding this comment.
이 문제는 반복문으로도 풀어보시면 좋을 것 같습니다! 그리고 항상 테스트 케이스를 기록하시는 모습이 인상 깊었고, 그 부분에서 많이 배웠습니다!
Comment on lines
+8
to
+24
| def productExceptSelfN(self, nums: List[int]) -> List[int]: | ||
| n = len(nums) | ||
| prefix, suffix, result = [0] * n, [0] * n, [0] * n | ||
|
|
||
| # Calculate prefix and suffix production | ||
| prefix[0], suffix[-1] = nums[0], nums[-1] | ||
| for i in range(1, n - 1): | ||
| prefix[i] = prefix[i - 1] * nums[i] | ||
| j = n - i - 1 | ||
| suffix[j] = suffix[j + 1] * nums[j] | ||
|
|
||
| # Update the result | ||
| result[0], result[-1] = suffix[1], prefix[-2] | ||
| for i in range(1, n - 1): | ||
| result[i] = prefix[i - 1] * suffix[i + 1] | ||
|
|
||
| return result |
Contributor
There was a problem hiding this comment.
저는 두 번째 풀이 방식으로 문제를 풀었는데, 이 풀이는 제가 생각하지 못했던 방법이라 보면서 공부가 되었습니다! 2주차도 고생하셨습니다 👍
Contributor
Author
There was a problem hiding this comment.
리뷰 너무 감사합니다! 이번주도 고생하셨고, 다음주도 화이팅입니다! 😄
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 하나 이상을 반드시 검토를 해주셔야 합니다!