-
-
Notifications
You must be signed in to change notification settings - Fork 248
Saysimple week4 #95
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
Saysimple week4 #95
Conversation
@saysimple0828 님, 다음 PR부터는 Iteration 표시해주시면 감사하겠습니다! (#71 참고) |
죄송합니다. 공지를 못봤군요 ㅠㅠ.. 넵 다음부터는 이터레이션을 달아서 올리도록 하겠습니다! |
|
||
class Solution: | ||
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.
count 메서드를 쓰니 한줄 코드가 되는군요!
|
||
class Solution: | ||
def reverseBits(self, n: int) -> int: | ||
return int(f"{bin(n)[2:]:0>32}"[::-1], 2) |
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.
혹시 코딩 테스트에서도 이렇게 간결하게 작성하는게 유리할까요?
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.
이래서 제가 비트 조작 문제는 실제 시험에 잘 안 나온다고 한 겁니다 ㅋㅋㅋ
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.
저는 약간 복잡하게 풀었는데 이 풀이 보니 엄청 직관적이네요! 배우고 갑니다.
@@ -0,0 +1,7 @@ | |||
# TC: O(n), SC: O(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.
i not in nums
에서 걸리는 시간을 과소 평가하신 게 아닐까요?
4주차 문제 풀이 완료!