-
Notifications
You must be signed in to change notification settings - Fork 3
Ksg2388 : [19week] #116
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
Open
ksg2388
wants to merge
5
commits into
main
Choose a base branch
from
ksg2388/19week
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ksg2388 : [19week] #116
Changes from 1 commit
Commits
Show all changes
5 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,48 @@ | ||
| # [155651] 호텔 대실 | ||
|
|
||
| ## :pushpin: **Algorithm** | ||
|
|
||
| 그리디, 우선순위 큐 | ||
|
|
||
| ## :round_pushpin: **Logic** | ||
|
|
||
| ```javascript | ||
| const change_time = book_time.map((time) => { | ||
| const startTime = time[0].split(':').map(Number); | ||
| const endTime = time[1].split(':').map(Number); | ||
| return [startTime[0] * 60 + startTime[1], endTime[0] * 60 + endTime[1]]; | ||
| }); | ||
| ``` | ||
|
|
||
| - 시작 시간별로 정렬을 하기위해 문자열을 분으로 변경했다. | ||
|
|
||
| ```javascript | ||
| change_time.forEach((time) => { | ||
| if (!q.length) { | ||
| q.push(time[1] + 10); | ||
| } | ||
|
|
||
| // 대실 가능한 빈 방이 없는 경우 | ||
| else if (q[q.length - 1] > time[0]) { | ||
| q.push(time[1] + 10); | ||
| } else { | ||
| // 대실 가능한 경우 | ||
| while (q.length) { | ||
| if (q[q.length - 1] <= time[0]) { | ||
| q.pop(); | ||
| } else break; | ||
| } | ||
| q.push(time[1] + 10); | ||
| } | ||
| q.sort((a, b) => b - a); | ||
| answer = Math.max(answer, q.length); | ||
| }); | ||
| ``` | ||
|
|
||
| - 다음 사람의 입실 시간과 가장 이른 퇴실 시간을 비교하여 입실 시간이 더 늦다면 새로운 방을 배정해준다. | ||
|
|
||
| ## :black_nib: **Review** | ||
|
|
||
| - 예전에 비슷한 문제를 풀어서 우선순위 큐를 이용해야겠다고 생각했다. | ||
| - 문자열이 정렬이 되지 않아서 일일히 분을 시간으로 치환해서 정렬을 했다. | ||
| - 문자열을 다루는데 시간을 너무 잡아먹은 것 같다... | ||
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,37 @@ | ||
| function solution(book_time) { | ||
| let answer = 1; | ||
| let q = []; | ||
|
|
||
| const change_time = book_time.map((time) => { | ||
| const startTime = time[0].split(':').map(Number); | ||
| const endTime = time[1].split(':').map(Number); | ||
| return [startTime[0] * 60 + startTime[1], endTime[0] * 60 + endTime[1]]; | ||
| }); | ||
|
|
||
| change_time.sort((a, b) => { | ||
| return a[0] - b[0]; | ||
| }); | ||
|
|
||
| change_time.forEach((time) => { | ||
| if (!q.length) { | ||
| q.push(time[1] + 10); | ||
| } | ||
|
|
||
| // 대실 가능한 빈 방이 없는 경우 | ||
| else if (q[q.length - 1] > time[0]) { | ||
| q.push(time[1] + 10); | ||
| } else { | ||
| // 대실 가능한 경우 | ||
| while (q.length) { | ||
| if (q[q.length - 1] <= time[0]) { | ||
| q.pop(); | ||
| } else break; | ||
| } | ||
| q.push(time[1] + 10); | ||
| } | ||
| q.sort((a, b) => b - a); | ||
| answer = Math.max(answer, q.length); | ||
| }); | ||
|
|
||
| return answer; | ||
| } |
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.
문자열에 강해져야겠네요 ㅎ 비중을 늘려봅시다