スポンサーリンク

【LeetCode】986. Interval List Intersections 解答・解説【Python】

スポンサーリンク
スポンサーリンク
この記事は約3分で読めます。

 

 

 

問題

原文

You are given two lists of closed intervals, firstList and secondList, where firstList[i] = [starti, endi] and secondList[j] = [startj, endj]. Each list of intervals is pairwise disjoint and in sorted order.

Return the intersection of these two interval lists.

A closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b.

The intersection of two closed intervals is a set of real numbers that are either empty or represented as a closed interval. For example, the intersection of [1, 3] and [2, 4] is [2, 3].

 

Example 1:

Example 2:

 

Constraints:

  • 0 <= firstList.length, secondList.length <= 1000
  • firstList.length + secondList.length >= 1
  • 0 <= starti < endi <= 109
  • endi < starti+1
  • 0 <= startj < endj <= 109
  • endj < startj+1

 

内容

2つの閉じた区間のリストが与えられます。それぞれのリストは[start, end]として開始~終了までの区間を表します。それぞれの区間は1:1で対応しており、ソートされています。

2つの区間の共通区間を返してください。

閉区間[a,b]は、a<=x<=bである実数xの集合を表します。

2つの閉区間の共通区間は、空であるか、閉区間として表現される実数の集合です。

例えば、[1,3]と[2,4]の共通区間は[2,3]になります。

 

※正しくない可能性があります。

 

解答

解答1:Python, two pointer

 

 

解答2:

 

 

 

メモ・参考・感想

 

 

 

前:844. Backspace String Compare

次:200. Number of Islands

LeetCode 解答・解説記事一覧

コメント