[tigermint] WEEK 08 Solutions - #2817
Open
tigermint wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
🏷️ 알고리즘 패턴 분석
longest-repeating-character-replacement/tigermint.kt
/**
TC: O(26n) = O(n)
SC: O(26) = O(1)
*/
class Solution {
fun characterReplacement(s: String, k: Int): Int {
var left = 0
val charToCount = mutableMapOf<Char, Int>()
var maxFrequency = 0
for (right in s.indices) {
val added = s[right]
charToCount[added] = (charToCount[added] ?: 0) + 1
// 교체 횟수가 k를 넘으면 왼쪽을 당겨 윈도우 축소
while ((right - left + 1) - charToCount.values.max() > k) {
val removed = s[left]
charToCount[removed] = charToCount.getValue(removed) - 1
left++
}
maxFrequency = maxOf(maxFrequency, right - left + 1)
}
return maxFrequency
}
}
- 패턴: Sliding Window, Hash Map / Hash Set
- 설명: 문자열 윈도우를 좌우로 이동시키며 길이를 최대화하는 방식으로, 창 크기 내 가장 빈도가 높은 문자를 추적하기 위해 해시 맵을 사용합니다. 조건을 만족하는지 확인하며 윈도우를 조정하는 슬라이딩 윈도우 패턴에 속합니다.
📊 시간/공간 복잡도 분석
ℹ️ 이 파일에는 2가지 풀이가 포함되어 있어 각각 분석합니다.
풀이 1: Solution.characterReplacement — Time: O(n) / Space: O(1)
| 복잡도 | |
|---|---|
| Time | O(n) |
| Space | O(1) |
피드백: 윈도우 내부 문자 빈도 수를 트래킹하고, 현재 윈도우의 최다빈도 문자를 기준으로 필요한 교체 횟수를 비교한다.
개선 제안: 현재 구현이 적절해 보입니다.
풀이 2: Solution.reverseBits — Time: O(1) / Space: O(1)
| 복잡도 | |
|---|---|
| Time | O(1) |
| Space | O(1) |
피드백: 상수 시간에 고정된 비트 수를 순회하며 뒤집는다.
개선 제안: 현재 구현이 적절해 보입니다.
💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!
Contributor
📊 tigermint 님의 학습 현황이번 주 제출 문제
누적 학습 요약
문제 풀이 현황
🤖 이 댓글은 GitHub App을 통해 자동으로 작성되었습니다. 🔢 API 사용량 (gpt-5-nano)
|
Contributor
There was a problem hiding this comment.
🏷️ 알고리즘 패턴 분석
reverse-bits/tigermint.kt
/**
TC: O(32) = O(1)
SC: O(1)
*/
class Solution {
fun reverseBits(n: Int): Int {
var result = 0
var num = n
repeat(32) {
result = (result shl 1) or (num and 1)
num = num ushr 1
}
return result
}
}
- 패턴: Bit Manipulation
- 설명: 정수의 비트를 반전시키며 앞뒤를 뒤집는 과정으로, 비트 연산과 시프트를 이용한 저수준 비트 조작 패턴이다. 반복문으로 32비트를 순회하며 값을 재배치한다.
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 하나 이상을 반드시 검토를 해주셔야 합니다!