-
-
Notifications
You must be signed in to change notification settings - Fork 245
[hj4645] WEEK 01 solutions #1688
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
contains-duplicate/hj4645.py
Outdated
# Time Complexity | ||
# - set(nums) → O(n) | ||
# - len(nums), len(set(nums)) → O(1) | ||
# - Total: O(n) (n = number of list elements) No newline at end of file |
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.
lint error 로 줄바꿈 검사 오류입니다. 마지막 줄 한 줄 추가해주세요.
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.
@printjin-gmailcom 안녕하세요
커밋 #f310a52로 개행문자 추가되어 있습니다
감사합니다!
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.
첫 주 수고하셨습니다. 2주차도 화이팅입니다 :)
# 순서가 보장되는 python dictionary를 사용해서, | ||
# 요소 x에 대해서 target-x 가 딕셔너리 내에 있는지를 찾는다. | ||
def twoSum(self, nums: List[int], target: int) -> List[int]: | ||
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.
dict는 파이썬 내장 타입이라 변수명으로 사용하면 좋지 않습니다. 참고 부탁드립니다
class Solution: | ||
# nums 에서 가장 빈도가 높은 k개의 요소를 찾는 문제 | ||
# 딕셔너리와 정렬을 사용해 해결 | ||
# 시간복잡도: O(n log n), 공간복잡도: O(n) |
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.
heapq나 bucket sort를 쓰면 O(n) 또는 O(n log k)로 더 빠르게 가능합니다. 물론 가독성과 정확성으로는 이 방법이 가장 좋아보이긴 합니다.
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.
리뷰가 늦었습니다... 이번 주도 수고하셨습니다!
# 리스트 안에 동일한 숫자가 2개 이상 존재하면 true를 반환해야 하는 문제 | ||
# Set으로 변환 시 중복이 제거되므로 List와 Set의 크기를 비교해 답을 구할 수 있음 | ||
def containsDuplicate(self, nums: List[int]) -> bool: | ||
return len(nums) != len(set(nums)) |
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.
저도 이런 로직으로 풀이해서 바로 이해가 되었습니다.
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!