Skip to content

[dahyeong-yun] WEEK 08 Solutions - #2811

Open
dahyeong-yun wants to merge 1 commit into
DaleStudy:mainfrom
dahyeong-yun:week-08
Open

[dahyeong-yun] WEEK 08 Solutions#2811
dahyeong-yun wants to merge 1 commit into
DaleStudy:mainfrom
dahyeong-yun:week-08

Conversation

@dahyeong-yun

@dahyeong-yun dahyeong-yun commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

Copy link
Copy Markdown
Contributor

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
/**
 * 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;       
    }
}
  • 패턴: Stack / Queue, Bit Manipulation
  • 설명: 주어진 코드는 32비트 정수를 비트를 스택에 쌓고, 다시 꺼내며 자리수에 따라 반전된 비트를 구성한다. 비트 단위 조작과 스택 사용으로 비트 반전의 과정을 다룬다.

📊 시간/공간 복잡도 분석

복잡도
Time O(1)
Space O(1)

피드백: 고정된 32비트 길이의 루프와 고정 크기 스택으로 구성되어 있어 시간과 공간이 상수로 보장된다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

@dalestudy

dalestudy Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

📊 dahyeong-yun 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
reverse-bits Easy ⚠️ 유형 불일치

누적 학습 요약

  • 풀이한 문제: 31 / 75개
  • 이번 주 유형 일치율: 0% (1문제 중 0문제 일치)

문제 풀이 현황

카테고리 진행도 완료
Array ■■■■■■□ 8 / 10 (Medium 5, Easy 3)
Dynamic Programming ■■■■■□□ 8 / 11 (Easy 1, Medium 7)
Matrix ■■■■□□□ 2 / 4 (Medium 2)
String ■■■■□□□ 5 / 10 (Medium 2, Easy 3)
Linked List ■■□□□□□ 2 / 6 (Easy 2)
Heap ■■□□□□□ 1 / 3 (Medium 1)
Graph ■■□□□□□ 2 / 8 (Medium 2)
Binary ■□□□□□□ 1 / 5 (Easy 1)
Tree ■□□□□□□ 2 / 14 (Easy 1, Medium 1)
Interval □□□□□□□ 0 / 5 ← 아직 시작 안 함

🤖 이 댓글은 GitHub App을 통해 자동으로 작성되었습니다.

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 388 82 470 $0.000052

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

한번 쉬프트 연산자를 활용해보시는건 어떨까요?
방금 저도 자바로 풀어봤는데 11줄까지 코드를 줄일수 있었어요!
if ((n & 1) == 1) answer |= 1;
이런 느낌으로 연산이 됩니다.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

또한 쉬프트연산자 쓰시면 별도의 스택같은 자료형이 필요 없기때문에 성능도 좋을거에요!

@JeonJe
JeonJe self-requested a review August 12, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Solving

Development

Successfully merging this pull request may close these issues.

2 participants