Skip to content

Merge Intervals#77

Open
Yuto729 wants to merge 1 commit into
mainfrom
merge-intervals
Open

Merge Intervals#77
Yuto729 wants to merge 1 commit into
mainfrom
merge-intervals

Conversation

@Yuto729

@Yuto729 Yuto729 commented Jun 1, 2026

Copy link
Copy Markdown
Owner

解く問題

Merge Intervals

次に解く問題

Comment thread merge-intervals/main.md
class Solution:
def merge(self, intervals: List[List[int]]) -> List[List[int]]:
sorted_intervals = sorted(intervals, key=lambda x: (x[0], x[1]))
stack = []

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

個人的には変数名にはデータ構造より、要素が何を表すかを付けることが多いです。自分なら merged_intervals と付けると思います。

Comment thread merge-intervals/main.md
stack = []
for interval in sorted_intervals:
if stack and stack[-1][1] >= interval[0]:
previous = stack.pop()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stack[-1][1] = max(stack[-1][1], interval[1])

としたほうがシンプルだと思いました。

Repository owner deleted a comment from github-actions Bot Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants