-
-
Notifications
You must be signed in to change notification settings - Fork 248
[chordpli] WEEK 02 solutions #1776
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
feat: 1주차 1,2 문제
* feat: 242 문제 * feat: 70 문제 * feat: leetcode / 15 / success / 투포인터
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[2] = 2 | ||
|
||
for i in range(3, n + 1): | ||
dp[i] = dp[i - 1] + dp[i - 2] |
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와 예외처리를 이용해서 깔끔하게 풀어주셨네요!
추가로 dp[i]
를 계산할 때 dp[i - 1]
과 dp[i - 2]
만 사용하기 때문에, O(n) space의 리스트가 아닌 O(1) space의 변수 두 개를 이용해서 공간 복잡도를 더 최적화 할 수도 있을 것 같습니다!
while left < right and nums[left] == nums[left + 1]: | ||
left += 1 | ||
while left < right and nums[right] == nums[right - 1]: | ||
right -= 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.
nums
를 정렬한 후 투 포인터 이동 시 중복된 원소는 건너뛰는 방식으로 최적화를 하신 것 같네요 🤩
dic = {} | ||
|
||
for num in nums: | ||
if dic.get(num): |
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.
num
이 dic
에 존재하는지만 O(1)에 확인하려면 dict()
가 아닌 set()
을 사용할 수도 있을 것 같아요!
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!