-
-
Notifications
You must be signed in to change notification settings - Fork 335
[sadie100] WEEK 08 Solutions #2558
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
Merged
Changes from all commits
Commits
Show all changes
4 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,34 @@ | ||
| /* | ||
| start, end 투 포인터 변수를 생성하고 end를 하나씩 늘려 가며 s를 탐색 | ||
| 글자별 개수를 저장하는 map, 최빈 등장수 maxCount를 통해 가장 많이 나온 캐릭터의 카운트를 저장하고 | ||
| 만약 end-start+1-maxCount가 k를 넘어가면 start를 +1한다 | ||
| 매번 end-start+1와 현 result를 비교하여 큰 값을 result로 갱신한다 | ||
|
|
||
| 시간복잡도 : O(N) | ||
| */ | ||
|
|
||
| function characterReplacement(s: string, k: number): number { | ||
| let start = 0 | ||
| let end = 0 | ||
| let result = 0 | ||
| let maxCount = 0 | ||
| const charMap = new Map() | ||
|
|
||
| while (end < s.length) { | ||
| const thisChar = s[end] | ||
| const updatedCount = (charMap.get(thisChar) || 0) + 1 | ||
| charMap.set(thisChar, updatedCount) | ||
| maxCount = Math.max(maxCount, updatedCount) | ||
|
|
||
| if (end - start + 1 - maxCount > k) { | ||
| const startChar = s[start] | ||
| charMap.set(startChar, charMap.get(startChar) - 1) | ||
| start += 1 | ||
| } | ||
|
|
||
| result = Math.max(result, end - start + 1) | ||
| end += 1 | ||
| } | ||
|
|
||
| return result | ||
| } |
|
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. 🏷️ 알고리즘 패턴 분석
|
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,19 @@ | ||
| /** | ||
| n의 뒤의 자리에서부터 비트로 변환해서 result에 붙이고, result 비트를 앞으로 당기는 일을 32번 반복해서 뒤집어진 비트를 만든다 | ||
|
|
||
| 시간복잡도 : O(1) - 비트 연산 | ||
| 공간복잡도 : O(1) | ||
| */ | ||
|
|
||
| function reverseBits(n: number): number { | ||
| let result = 0 | ||
|
|
||
| for (let i = 0; i < 32; i++) { | ||
| const bit = n & 1 | ||
|
|
||
| result = (result << 1) | bit | ||
|
|
||
| n = n >>> 1 | ||
| } | ||
| return result >>> 0 | ||
| } |
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.
🏷️ 알고리즘 패턴 분석