美文网首页
python测试开发20-合并重叠区间(facebook面试题)

python测试开发20-合并重叠区间(facebook面试题)

作者: python测试开发 | 来源:发表于2021-05-15 06:51 被阅读0次

    面试题

    给定区间的列表,合并所有重叠的区间。

    Given [1,3],[2,6],[8,10],[15,18],
    return [1,6],[8,10],[15,18].

    英文原文:

    Find the contiguous subarray within an array (containing at least one number) which has the largest sum.

    For example, given the array [−2,1,−3,4,−1,2,1,−5,4],
    the contiguous subarray [4,−1,2,1] has the largest sum = 6.

    参考答案

    先将区间按照start的值来排序,再判断区间的start值是否处在前一个区间中,如果在前一个区间中就合并,反之添加新区间。

    参考资料

    相关文章

      网友评论

          本文标题:python测试开发20-合并重叠区间(facebook面试题)

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