码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-03-04 00:24:15      阅读:381      评论:0      收藏:0      [点我收藏+]

标签:nbsp   als   nat   and   nts   intersect   elements   eve   exp   

 

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

标签:nbsp   als   nat   and   nts   intersect   elements   eve   exp   

原文地址:https://www.cnblogs.com/grandyang/p/8503476.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!