[LeetCode] Set Intersection Size At Least Two 设置交集大小至少为2

Posted Grandyang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[LeetCode] Set Intersection Size At Least Two 设置交集大小至少为2相关的知识,希望对你有一定的参考价值。

 

An integer interval [a, b] (for integers a < b) is a set of all consecutive integers from a to b, including a and b.

Find the minimum size of a set S such that for every integer interval A in intervals, the intersection of S with A has size at least 2.

Example 1:

Input: intervals = [[1, 3], [1, 4], [2, 5], [3, 5]]
Output: 3
Explanation:
Consider the set S = {2, 3, 4}.  For each interval, there are at least 2 elements from S in the interval.
Also, there isn‘t a smaller size set that fulfills the above condition.
Thus, we output the size of this set, which is 3.

 

Example 2:

Input: intervals = [[1, 2], [2, 3], [2, 4], [4, 5]]
Output: 5
Explanation:
An example of a minimum sized set is {1, 2, 3, 4, 5}.

 

Note:

  1. intervals will have length in range [1, 3000].
  2. intervals[i] will have length 2, representing some integer interval.
  3. intervals[i][j] will be an integer in [0, 10^8].

 

s

 

以上是关于[LeetCode] Set Intersection Size At Least Two 设置交集大小至少为2的主要内容,如果未能解决你的问题,请参考以下文章

Python Set intersection() 方法

LeetCode:Intersection of Two Linked Lists

[LeetCode] Intersection of Two Arrays II

[leetcode]349.Intersection of Two Arrays

LeetCode:Intersection of Two Arrays II

Leetcode 350. Intersection of Two Arrays II