美文网首页
436. Find Right Interval

436. Find Right Interval

作者: 阿团相信梦想都能实现 | 来源:发表于2016-12-22 03:46 被阅读0次
    # Definition for an interval.
    # class Interval(object):
    #     def __init__(self, s=0, e=0):
    #         self.start = s
    #         self.end = e
    
    class Solution(object):
        def findRightInterval(self, intervals):
            """
            :type intervals: List[Interval]
            :rtype: List[int]
            """
            l=sorted((interval.start,pos) for pos,interval in enumerate(intervals))
            res=[]
            for i in intervals:
                #locate the first interval.start that's bigger than i.end 
                r=bisect.bisect(l,(i.end,))
                
                res.append(l[r][1] if r<len(intervals) else -1)
            return res
    

    相关文章

      网友评论

          本文标题:436. Find Right Interval

          本文链接:https://www.haomeiwen.com/subject/mpecvttx.html