暴搜..

class Solution(object):
    def intervalIntersection(self, A: List[Interval], B: List[Interval]) -> List[Interval]:
        """
        :type A: List[Interval]
        :type B: List[Interval]
        :rtype: List[Interval]
        """
        ans = []
        for interval_b in B:
            for interval_a in A:
                t = self.intersection(interval_a, interval_b)
                if t:
                    ans.append(t)
        return ans

    def intersection(self, a: Interval, b: Interval):
        if a.end < b.start or b.end < a.start:
            return None
        return Interval(max(a.start, b.start), min(a.end, b.end))

 

相关文章:

  • 2021-09-08
  • 2021-11-23
  • 2022-01-23
  • 2021-07-16
  • 2021-11-25
  • 2022-01-09
猜你喜欢
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2021-06-09
  • 2021-06-22
  • 2022-12-23
相关资源
相似解决方案