Skip to content

[hak.lee] week 1 #305

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

Merged
merged 2 commits into from
Aug 16, 2024
Merged

[hak.lee] week 1 #305

merged 2 commits into from
Aug 16, 2024

Conversation

haklee
Copy link
Contributor

@haklee haklee commented Aug 11, 2024

No description provided.

Comment on lines +3 to +12
ref: https://wiki.python.org/moin/TimeComplexity
set는 dict와 거의 비슷하게 구현되어 있는데,
dict의 `Set Item`의 Average Case는 O(1)이더라도
Amortized Worst Case가 O(n)이다!

즉, set에 아이템을 추가할때마다 해시 충돌이 일어날 경우
최악의 경우 O(n^2)이 걸리므로, 아래의 set(nums)의
TC가 O(n^2)이 되는 것일까..?

set(nums)의 결과가 최악의 경우 SC가 O(n)이다.
Copy link
Member

Choose a reason for hiding this comment

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

일반적으로 코딩 테스트에서는 이 정도까지 깊은 복잡도 분석을 요하지는 않습니다. 대부분의 개발자들은 해시 충돌이 거의 일어나지 않는다는 것을 가정하고 해시 테이블 기반의 자료 구조를 사용합니다. 따라서 이 풀이의 시간 복잡도는 O(n)라고 하시더라도 면접관과 크게 논쟁의 여지는 없을 것 같습니다.

class Solution:
def topKFrequent(self, nums: List[int], n: int) -> List[int]:
d = {}
[d.update({i: d.get(i, 0) + 1}) for i in nums]
Copy link
Contributor

Choose a reason for hiding this comment

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

해당 코드도 충분히 좋아보입니다만, collections 모듈을 써서 가독성을 높이는거도 좋아보입니다 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Counter를 써서 한 줄 솔루션으로 바꿔보았습니다!

@yolophg
Copy link
Contributor

yolophg commented Aug 12, 2024

안녕하세요, 코치 Helena 입니다.
아래 사진과 같이 Projects 에서 iteration 설정도 같이 부탁드립니다!
이번엔 제가 해두었는데, 원할한 스터디 그룹 진도 관리와 통계를 위해서 중요한 부분이니 다음 이터레이션부터는 해주시면 감사드리겠습니다 :)
Screenshot 2024-08-12 at 11 41 08

@SamTheKorean SamTheKorean merged commit 0cabff3 into DaleStudy:main Aug 16, 2024
@taekwon-dev taekwon-dev added the py label Aug 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

7 participants