-
-
Notifications
You must be signed in to change notification settings - Fork 195
[Lyla] Week 1 #634
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
[Lyla] Week 1 #634
Conversation
Sam 님 도움으로 권한 부여받았습니다! |
팀 초대가 누락되어있었습니다! 제가 초대드렸으니 초대 수락 후 확인 부탁드립니다! |
@SamTheKorean 초대 수락했습니다! 감사합니다 :) |
@@ -0,0 +1,3 @@ | |||
class Solution: | |||
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.
😮 python은 이렇게 set 자료구조를 간편하게 쓸 수 있어 너무 깔끔하게 처리되는군요.
@SamTheKorean 안녕하세요. 파일명을 깃허브 author 로 해놨는데도 계속 린트 에러가 나는 것 같아요. 혹시 짐작되는 에러 원인이 있을까요? |
@pmjuu 안녕하세요 |
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.
temp = prev1 | ||
prev1 = max(prev2 + num, prev1) # 현재 집을 털었을 때와 안 털었을 때 중 더 큰 이익 선택 | ||
prev2 = temp |
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.
(안 중요) 요렇게 좀 더 Pythonic 하게 코드를 작성하시면 다른 언어처럼 임시 변수를 안 쓰고 변수의 값을 스왑할 수 있을 것 같아요.
temp = prev1 | |
prev1 = max(prev2 + num, prev1) # 현재 집을 털었을 때와 안 털었을 때 중 더 큰 이익 선택 | |
prev2 = temp | |
prev1, prev2 = max(prev2 + num, prev1), prev1 |
# 빈도가 높은 순서대로 k개의 숫자를 추출 | ||
result = [] | ||
for freq in range(n, 0, -1): | ||
if buckets[freq]: | ||
result.extend(buckets[freq]) | ||
|
||
if len(result) == k: | ||
return result |
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.
보통 이 문제는 다들 정렬이나 힙을 사용해서 많이 푸시는데, 배열을 사용하셔서 좀 더 효과적으로 해결하셨군요!
result
리스트 안에 원소가 k
개가 되자 마자 바로 반환하는 최적화 센스도 너무 좋으세요! 👍
알고리즘 고수의 향기를 맡고 갑니다 🌸
@DaleSeo 피드백 감사드려요! 다음부터는 시간/공간 복잡도를 주석으로 달아볼게요. 이 방법에 저한테도 더 편할 것 같네요 ㅎㅎ 리뷰 감사합니다~! |
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.