Skip to content

[ICE0208] WEEK 08 Solutions - #2818

Open
ICE0208 wants to merge 3 commits into
DaleStudy:mainfrom
ICE0208:week08
Open

[ICE0208] WEEK 08 Solutions#2818
ICE0208 wants to merge 3 commits into
DaleStudy:mainfrom
ICE0208:week08

Conversation

@ICE0208

@ICE0208 ICE0208 commented Aug 15, 2026

Copy link
Copy Markdown
Member

답안 제출 문제

작성자 체크 리스트

  • 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.

🏷️ 알고리즘 패턴 분석

longest-repeating-character-replacement/ICE0208.java
class Solution {
    public int characterReplacement(String s, int k) {
        int[] frequency = new int[26];
        int maxFrequency = 0;
        int left = 0;
        int maxLength = 0;

        for (int right = 0; right < s.length(); right++) {
            int index = s.charAt(right) - 'A';
            frequency[index]++;

            // maxFrequency 갱신
            maxFrequency = Math.max(maxFrequency, frequency[index]);

            // right - left + 1 - maxFrequency : 현재 위도우에서 maxFrequency를 제외한 개수
            while (right - left + 1 - maxFrequency > k) {
                frequency[s.charAt(left) - 'A']--;
                left++;
            }

            maxLength = Math.max(maxLength, right - left + 1);
        }
        return maxLength;
    }
}
  • 패턴: Sliding Window, Greedy
  • 설명: 길이 k 이내로 문자를 바꿔 최장 같은 문자 부분 문자열 길이를 구하는 방식으로, 창 크기를 조정하며 현재 윈도우에서의 최대 빈도수를 유지하는 Sliding Window 패턴과 조건을 만족하는 최장 길이를 구하기 위한 탐욕적 접근(Greedy)의 조합으로 판단됩니다.

📊 시간/공간 복잡도 분석

ℹ️ 이 파일에는 2가지 풀이가 포함되어 있어 각각 분석합니다.

풀이 1: Solution.characterReplacement — Time: O(n) / Space: O(1)
복잡도
Time O(n)
Space O(1)

피드백: 고정된 알파벳 크기 26으로 freq를 관리하고, 윈도우를 한 방향으로 확장하면서 필요 시 좌측 포인터를 이동시킨다.

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

풀이 2: Solution.reverseBits — Time: O(32) / Space: O(1)
복잡도
Time O(32)
Space O(1)

피드백: 문자열 변환과 역순 문자열로의 변환을 통해 비트를 반전시키는 직관적 방법이다.

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

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

@dalestudy

dalestudy Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

📊 ICE0208 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
longest-repeating-character-replacement Medium ✅ 의도한 유형
reverse-bits Easy ⚠️ 유형 불일치

누적 학습 요약

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

문제 풀이 현황

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

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

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 696 74 770 $0.000064
2 812 90 902 $0.000077
합계 1,508 164 1,672 $0.000141

Comment thread reverse-bits/ICE0208.java

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/ICE0208.java
class Solution {
    public int reverseBits(int n) {
        String binary = String.format("%32s", Integer.toBinaryString(n))
                .replace(' ', '0');

        String reversed = new StringBuilder(binary)
                .reverse()
                .toString();

        return Integer.parseUnsignedInt(reversed, 2);
    }
}
  • 패턴: Bit Manipulation, Divide and Conquer
  • 설명: 주어진 코드는 비트를 문자열로 다루어 32비트 이진 표현을 뒤집은 후 다시 정수로 해석한다. 비트 단위 변환과 역순 처리로 비트 조작 패턴에 해당하며, 문자열 기반으로 구현되지만 핵심은 비트 조작 아이디어를 활용한다.

@parkhojeong
parkhojeong self-requested a review August 15, 2026 11:14
Comment thread reverse-bits/ICE0208.java

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/ICE0208.java
class Solution2 {
    public int reverseBits(int n) {
        int result = 0;

        for (int i = 0; i < 32; i++) {
            int lastBit = n & 1; // 가장 오른쪽 비트 추출

            result <<= 1;        // 새 비트를 넣을 자리 확보
            result |= lastBit;   // 추출한 비트를 오른쪽 끝에 추가

            n >>>= 1;            // 처리한 비트를 버림.
        }

        return result;
    }
}

class Solution {
    public int reverseBits(int n) {
        String binary = String.format("%32s", Integer.toBinaryString(n))
                .replace(' ', '0');

        String reversed = new StringBuilder(binary)
                .reverse()
                .toString();

        return Integer.parseUnsignedInt(reversed, 2);
    }
}
  • 패턴: Bit Manipulation, Two Pointers
  • 설명: 첫 풀이에서 비트를 왼쪽으로 시프트하고 마지막 비트를 추출해 반대로 뒤집는 방식은 비트 조작(Bit Manipulation)이며, 비트를 순차적으로 다루어 반전 위치를 맞추는 형태로 볼 수 있습니다. 두 번째 풀이도 비트를 문자열로 다루는 비트 조작의 변형으로 해석할 수 있습니다.

📊 시간/공간 복잡도 분석

ℹ️ 이 파일에는 2가지 풀이가 포함되어 있어 각각 분석합니다.

풀이 1: Solution2.reverseBits — Time: O(32) / Space: O(1)
복잡도
Time O(32)
Space O(1)

피드백: 정수의 각 비트를 차례대로 반전시켜 누적 결과를 생성하는 방법으로, 고정된 32비트에 대해 일정한 시간과 상수 공간을 사용합니다.

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

풀이 2: Solution.reverseBits — Time: O(32) / Space: O(32)
복잡도
Time O(32)
Space O(32)

피드백: 문자열 변환과 파싱으로 구현했지만 비트 연산 기반 방법보다 상수 공간을 더 많이 사용할 수 있으며, 비트 조작에 의존하는 것이 일반적입니다.

개선 제안: 고려해볼 만한 대안: 비트 연산만으로 구현하는 방법으로 리팩토링

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

@parkhojeong parkhojeong left a comment

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.

수고하셨습니다.

Comment on lines +16 to +21
while (right - left + 1 - maxFrequency > k) {
frequency[s.charAt(left) - 'A']--;
left++;
}

maxLength = Math.max(maxLength, right - left + 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.

right - left + 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.

심플하게 풀어주셔서 이해가 잘 되네요

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

2 participants