zoukankan      html  css  js  c++  java
  • Leetcode 986. Interval List Intersections

    暴搜..

    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))
  • 相关阅读:
    申请奖励加分
    6.14
    6.11
    6.10
    6.9
    6.8
    6.7
    6.6
    6.5
    6.4
  • 原文地址:https://www.cnblogs.com/zywscq/p/10674653.html
Copyright © 2011-2022 走看看