-
-
Notifications
You must be signed in to change notification settings - Fork 361
[dahyeong-yun] WEEK 08 Solutions #2811
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
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. 한번 쉬프트 연산자를 활용해보시는건 어떨까요?
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. 또한 쉬프트연산자 쓰시면 별도의 스택같은 자료형이 필요 없기때문에 성능도 좋을거에요! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /** | ||
| * TC : O(1) | ||
| * - 32번의 루프를 2번 반복하므로 O(1) | ||
| * SC : O(1) | ||
| * - 32칸 고정 길이의 stack이 필요하므로 O(1) | ||
| */ | ||
|
|
||
| class Solution { | ||
| public int reverseBits(int n) { | ||
| int answer = 0; | ||
| Deque<Integer> stack = new ArrayDeque<>(); | ||
|
|
||
| for(int i = 0; i<32; i++) { | ||
| stack.add(n % 2); | ||
| n /= 2; | ||
| } | ||
|
|
||
| int j = 0; | ||
| while(!stack.isEmpty()) { | ||
| int bit = stack.getLast(); | ||
| stack.removeLast(); | ||
| answer += bit * Math.pow(2, j); | ||
| j += 1; | ||
| } | ||
|
|
||
| return answer; | ||
| } | ||
| } |
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/dahyeong-yun.java
📊 시간/공간 복잡도 분석
피드백: 고정된 32비트 길이의 루프와 고정 크기 스택으로 구성되어 있어 시간과 공간이 상수로 보장된다.
개선 제안: 현재 구현이 적절해 보입니다.