-
-
Notifications
You must be signed in to change notification settings - Fork 245
[hu6r1s] WEEK 03 Solutions #1784
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
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.
수고하셨습니다! 다음주도 화이팅입니다 ;)
최종 공간 복잡도: O(log n) | ||
""" | ||
def hammingWeight(self, n: int) -> int: | ||
return bin(n).count('1') |
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.
bin()이 문자열을 새로 생성하기 때문에 매우 큰 수가 연속적으로 많이 호출되면 약간의 오버헤드가 있을 수 있음 참고
- 길이 n+1짜리 dp 배열 사용 | ||
- 공간 최적화를 하면 O(1)로 줄일 수 있음 | ||
""" | ||
dp = [0] * len(s) + [1] |
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.
dp = [0] * (len(s) + 1)
dp[len(s)] = 1
이렇게 나누는게 가독성 측면에서 좋지 않을까 남겨봅니다.
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!