Skip to content
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

Merged
merged 1 commit into from
May 31, 2024
Merged

Conversation

bhyun-kim
Copy link
Contributor

No description provided.

- Storing the output: O(k)
k <= n
"""
from collections import OrderedDict
Copy link
Contributor

@SamTheKorean SamTheKorean May 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 sort메서드를 사용하는데 OrderDict을 사용한 이유가 있을까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

처음 접근할 때 OrderedDict()이 아니면 sorted 를 못쓰는 줄 알고 그렇게 작성했었어요. 그냥 dict()로 바꿔도 잘 실행되네요! 감사합니다.

Copy link
Contributor

@DaleSeo DaleSeo May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

참고로 OrderedDict에서 Ordered의 의미는 데이터를 사전에 추가한 순서 그대로 저장해준다는 의미입니다. 즉, 오름차순/내림차순 정렬과는 아무 관련이 없습니다.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

orderdict을 잘 몰랐는데 설명 감사드립니다!

Copy link
Contributor

@SamTheKorean SamTheKorean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이번주도 고생많으셨습니다!

@DaleSeo
Copy link
Contributor

DaleSeo commented May 31, 2024

@bhyun-kim 님, Iteration 설정 좀 부탁드리겠습니다!

@bhyun-kim
Copy link
Contributor Author

@bhyun-kim 님, Iteration 설정 좀 부탁드리겠습니다!

설정 완료했습니다! 자꾸 깜빡하네요 ㅠㅠ

Copy link
Contributor

@DaleSeo DaleSeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨어요!

Comment on lines +71 to +73
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])
Copy link
Contributor

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에 저장할 수 있거든요.

Comment on lines +5 to +28
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]
Copy link
Contributor

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
Copy link
Contributor

@DaleSeo DaleSeo May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

참고로 OrderedDict에서 Ordered의 의미는 데이터를 사전에 추가한 순서 그대로 저장해준다는 의미입니다. 즉, 오름차순/내림차순 정렬과는 아무 관련이 없습니다.

Copy link
Contributor

@SamTheKorean SamTheKorean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이번 주도 고생많으셨습니다!

@leokim0922 leokim0922 merged commit 5105c56 into DaleStudy:main May 31, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants