-
Notifications
You must be signed in to change notification settings - Fork 0
252: Meeting Rooms #55
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
garunitule
wants to merge
1
commit into
main
Choose a base branch
from
252
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.
+62
−0
Open
Changes from all commits
Commits
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,62 @@ | ||
| # 進め方 | ||
| - step1: 5分考えて分からなかったら答えを見る。答えを理解したら、答えを隠して書く。筆が進まず5分立ったら答えを見る。答えを送信して正解するまで。 | ||
| - step2: コードを読みやすく整える。動くコードになったら終了。 | ||
| - step3: 時間を計りながら書く。10分以内に3回連続でアクセプトされるまで。 | ||
|
|
||
| # step1: 15分 | ||
| ## 方針を考える | ||
| startでソートして、i番目のアイテムのendとi+1番目のアイテムのstartについて、end <= startが成立するか確認すれば解けそう。 | ||
|
|
||
| O(n)で解ける方法がないか検討したけど思いつかなかった。 | ||
|
|
||
| ## 実装 | ||
| ```python | ||
| class Solution: | ||
| def canAttendMeetings(self, intervals: List[List[int]]) -> bool: | ||
| intervals_sorted_by_start = sorted(intervals, key=lambda interval: interval[0]) | ||
| for i in range(len(intervals_sorted_by_start) - 1): | ||
| if intervals_sorted_by_start[i][1] > intervals_sorted_by_start[i + 1][0]: | ||
| return False | ||
| return True | ||
| ``` | ||
|
|
||
| # step2: 30分 | ||
| leetcodeの解法を見たら、全組み合わせを確認する解法とソートして確認する解法だった。 | ||
| Pythonだと空間計算量はO(n)だけど、JavaだとO(logn)とのこと。実装アルゴリズムが異なるらしい。 | ||
|
|
||
|
|
||
| # step3: 15分 | ||
| ※間違えがあればn回目を増やす | ||
|
|
||
| ## 1回目 | ||
| ```python | ||
| class Solution: | ||
| def canAttendMeetings(self, intervals: List[List[int]]) -> bool: | ||
| intervals_sorted_by_start = sorted(intervals, key=lambda interval: interval[0]) | ||
| for i in range(len(intervals_sorted_by_start) - 1): | ||
| if intervals_sorted_by_start[i][1] > intervals_sorted_by_start[i + 1][0]: | ||
| return False | ||
| return True | ||
| ``` | ||
|
|
||
| ## 2回目 | ||
| ```python | ||
| class Solution: | ||
| def canAttendMeetings(self, intervals: List[List[int]]) -> bool: | ||
| intervals_sorted_by_started = sorted(intervals, key=lambda interval: interval[0]) | ||
| for i in range(len(intervals_sorted_by_started) - 1): | ||
| if intervals_sorted_by_started[i][1] > intervals_sorted_by_started[i + 1][0]: | ||
| return False | ||
| return True | ||
| ``` | ||
|
|
||
| ## 3回目 | ||
| ```python | ||
| class Solution: | ||
| def canAttendMeetings(self, intervals: List[List[int]]) -> bool: | ||
| intervals_sorted_by_start = sorted(intervals, key=lambda interval: interval[0]) | ||
| for i in range(len(intervals_sorted_by_start) - 1): | ||
|
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.
|
||
| if intervals_sorted_by_start[i][1] > intervals_sorted_by_start[i + 1][0]: | ||
| return False | ||
| return True | ||
| ``` | ||
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.
何のことかと思ってGeminiに聞いてみたところ
ということなんですね(裏取りできていませんが)。