-
-
Notifications
You must be signed in to change notification settings - Fork 361
[freemjstudio] WEEK 09 Solutions #2821
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
Open
freemjstudio
wants to merge
1
commit into
DaleStudy:main
Choose a base branch
from
freemjstudio:freemjstudio-week09
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+14
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| class Solution: | ||
| def reverseBits(self, n: int) -> int: | ||
| # 1. convert integer into binary | ||
| binary = bin(n)[2:] | ||
|
|
||
| # 2. convert into 32bits | ||
| fill_zero = 32 - len(binary) | ||
| binary = "0" * fill_zero + binary | ||
|
|
||
| # 3. reverse the binary | ||
| reversed_binary = binary[::-1] | ||
|
|
||
| # 4. convert binary into integer | ||
| return int(reversed_binary,2) | ||
|
Comment on lines
+3
to
+14
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 문자열 조작 없이 비트 연산과 같은 방식 등으로 풀어보셔도 좋을 거 같습니다. |
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🏷️ 알고리즘 패턴 분석
reverse-bits/freemjstudio.py
📊 시간/공간 복잡도 분석
피드백: 정수의 이진 표현을 문자열로 다루고 왼쪽 패딩과 반전을 통해 역순 이진수를 얻는다.
개선 제안: 현재 구현은 직관적이지만, 비트 연산만으로 32비트 반전을 수행하면 더 빠르고 메모리 효율적이다. 예: 비트 마스크와 쉬프트를 이용한 역순 연산으로 O(1) 시간 복잡도를 유지할 수 있다.