[ICE0208] WEEK 08 Solutions - #2818
Open
ICE0208 wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
🏷️ 알고리즘 패턴 분석
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) |
피드백: 문자열 변환과 역순 문자열로의 변환을 통해 비트를 반전시키는 직관적 방법이다.
개선 제안: 현재 구현이 적절해 보입니다.
💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!
Contributor
📊 ICE0208 님의 학습 현황이번 주 제출 문제
누적 학습 요약
문제 풀이 현황
🤖 이 댓글은 GitHub App을 통해 자동으로 작성되었습니다. 🔢 API 사용량 (gpt-5-nano)
|
Contributor
There was a problem hiding this comment.
🏷️ 알고리즘 패턴 분석
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
self-requested a review
August 15, 2026 11:14
Contributor
There was a problem hiding this comment.
🏷️ 알고리즘 패턴 분석
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
approved these changes
Aug 15, 2026
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); |
Contributor
There was a problem hiding this comment.
right - left + 1 부분을 변수로 선언하는 건 어떨까요?
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!