-
-
Notifications
You must be signed in to change notification settings - Fork 361
[tigermint] WEEK 08 Solutions #2817
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
Merged
+42
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /** | ||
| 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 | ||
| } | ||
| } |
|
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. 🏷️ 알고리즘 패턴 분석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
}
}
Member
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. 코틀린의 비트 연산자는 엄청 직관적이네요!! |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /** | ||
| 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 | ||
| } | ||
| } |
Oops, something went wrong.
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.
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.
🏷️ 알고리즘 패턴 분석
longest-repeating-character-replacement/tigermint.kt
📊 시간/공간 복잡도 분석
풀이 1:
Solution.characterReplacement— Time: O(n) / Space: O(1)피드백: 윈도우 내부 문자 빈도 수를 트래킹하고, 현재 윈도우의 최다빈도 문자를 기준으로 필요한 교체 횟수를 비교한다.
개선 제안: 현재 구현이 적절해 보입니다.
풀이 2:
Solution.reverseBits— Time: O(1) / Space: O(1)피드백: 상수 시간에 고정된 비트 수를 순회하며 뒤집는다.
개선 제안: 현재 구현이 적절해 보입니다.