-
Notifications
You must be signed in to change notification settings - Fork 126
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
[bhyun-kim, 김병현] Week 5 Solutions #103
Conversation
- Storing the output: O(k) | ||
k <= n | ||
""" | ||
from collections import OrderedDict |
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.
혹시 sort메서드를 사용하는데 OrderDict을 사용한 이유가 있을까요?
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.
처음 접근할 때 OrderedDict()이 아니면 sorted 를 못쓰는 줄 알고 그렇게 작성했었어요. 그냥 dict()로 바꿔도 잘 실행되네요! 감사합니다.
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.
참고로 OrderedDict
에서 Ordered
의 의미는 데이터를 사전에 추가한 순서 그대로 저장해준다는 의미입니다. 즉, 오름차순/내림차순 정렬과는 아무 관련이 없습니다.
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.
orderdict을 잘 몰랐는데 설명 감사드립니다!
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.
이번주도 고생많으셨습니다!
@bhyun-kim 님, Iteration 설정 좀 부탁드리겠습니다! |
설정 완료했습니다! 자꾸 깜빡하네요 ㅠㅠ |
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.
수고하셨어요!
if not f"[{n_i},{n_low},{n_high}]" in prevs: | ||
prevs[f"[{n_i},{n_low},{n_high}]"] = 1 | ||
output.append([n_i, n_low, n_high]) |
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.
dictionary 말고 set 자료 구조를 쓰셨다면 좀 더 깔끔하게 중복 체크가 되지 않았을까요?
list 대신에 tuple을 사용하시면 set에 저장할 수 있거든요.
Solution: | ||
- Create two lists to store the product of elements from the left and right | ||
- Multiply the elements from the left and right lists to get the output | ||
|
||
Example: | ||
nums = [4, 2, 3, 1, 7, 0, 9, 10] | ||
|
||
left is numbers to the left of the current index | ||
right is numbers to the right of the current index | ||
from_left is the product of the numbers to the left of the current index | ||
from_right is the product of the numbers to the right of the current index | ||
|
||
i = 0: (4) 2 3 1 7 0 9 10 | ||
i = 1: 4 (2) 3 1 7 0 9 10 | ||
i = 2: 4 2 (3) 1 7 0 9 10 | ||
i = 3: 4 2 3 (1) 7 0 9 10 | ||
i = 4: 4 2 3 1 (7) 0 9 10 | ||
i = 5: 4 2 3 1 7 (0) 9 10 | ||
i = 6: 4 2 3 1 7 0 (9) 10 | ||
i = 7: 4 2 3 1 7 0 9 (10) | ||
|
||
from_left = [0, 4, 8, 24, 24, 168, 0, 0] | ||
from_right = [0, 0, 0, 0, 0, 90, 10, 0] | ||
output = [0, 0, 0, 0, 0, 15120, 0, 0] |
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.
설명과 시각화 좋네요 👍
- Storing the output: O(k) | ||
k <= n | ||
""" | ||
from collections import OrderedDict |
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.
참고로 OrderedDict
에서 Ordered
의 의미는 데이터를 사전에 추가한 순서 그대로 저장해준다는 의미입니다. 즉, 오름차순/내림차순 정렬과는 아무 관련이 없습니다.
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.
이번 주도 고생많으셨습니다!
No description provided.