Skip to content

Conversation

say828
Copy link

@say828 say828 commented May 25, 2024

4주차 문제 풀이 완료!

@DaleSeo
Copy link
Member

DaleSeo commented May 26, 2024

@saysimple0828 님, 다음 PR부터는 Iteration 표시해주시면 감사하겠습니다! (#71 참고)
이 번 PR에는 제가 대신 해드리겠습니다 :)

@say828
Copy link
Author

say828 commented May 26, 2024

죄송합니다. 공지를 못봤군요 ㅠㅠ.. 넵 다음부터는 이터레이션을 달아서 올리도록 하겠습니다!


class Solution:
def hammingWeight(self, n: int) -> int:
return bin(n).count("1")
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

혹시 코딩 테스트에서도 이렇게 간결하게 작성하는게 유리할까요?

Copy link
Member

Choose a reason for hiding this comment

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

이래서 제가 비트 조작 문제는 실제 시험에 잘 안 나온다고 한 겁니다 ㅋㅋㅋ

Copy link
Contributor

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)
Copy link
Member

@DaleSeo DaleSeo May 28, 2024

Choose a reason for hiding this comment

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

i not in nums에서 걸리는 시간을 과소 평가하신 게 아닐까요?

@DaleSeo DaleSeo merged commit 9ee7b25 into DaleStudy:main May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants