Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
(Formally, a closed interval
[a, b]
(witha <= b
) denotes the set of real numbersx
witha <= x <= b
. The intersection of two closed intervals is a set of real numbers that is either empty, or can be represented as a closed interval. For example, the intersection of [1, 3] and [2, 4] is [2, 3].)
Note:
0 <= A.length < 1000
0 <= B.length < 1000
0 <= A[i].start, A[i].end, B[i].start, B[i].end < 10^9
NOTE: input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.
給予兩個封閉區間的串列,每個區間都成對且不相交,並照順序排列。
回傳兩個區間串列中重疊的部分。
(通常,一個封閉區間
[a, b]
(其中a <= b
)意味著一個實數集合x
且a <= x <= b
。兩個封閉區間的重疊區域也是一個實數集合,它可以是空的也可以是一個封閉區間。例如,[1, 3]和[2, 4]的重疊區間就是[2, 3]。)
注意:
0 <= A.length < 1000
0 <= B.length < 1000
0 <= A[i].start, A[i].end, B[i].start, B[i].end < 10^9
注意:
輸入格式在2019年4月15日更動,請重置成預設程式碼以得到新的方法。
A
和B
合併起來並排序。
out
存下第一個區間的尾,然後接下來只有幾種情況:
A[i][0] > out
out
。A[i][1] < out
A[i][1] > out
out
LeetCode
C++