面试题
给定区间的列表,合并所有重叠的区间。
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值是否处在前一个区间中,如果在前一个区间中就合并,反之添加新区间。

- 源码地址 https://github.com/china-testing/python-testing-examples interview/ merge_intervals.py
- 本文涉及的python测试开发库 谢谢点赞!
- 本文相关海量书籍下载
网友评论