57. Insert Interval

iven a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).

You may assume that the intervals were initially sorted according to their start times.

Example 1:
Given intervals [1,3],[6,9], insert and merge [2,5] in as [1,5],[6,9].

Example 2:
Given [1,2],[3,5],[6,7],[8,10],[12,16], insert and merge [4,9] in as [1,2],[3,10],[12,16].

This is because the new interval [4,9] overlaps with [3,5],[6,7],[8,10].



vector<Interval> insert(vector<Interval>& intervals, Interval newInterval) {
    vector<Interval> res;
    int i = 0;
    int n = intervals.size();
    while (i < n&&newInterval.start > intervals[i].end)  res.push_back(intervals[i++]);
    newInterval.start = ((i == n) ? newInterval.start : min(newInterval.start, intervals[i].start));
    while (i < n&&newInterval.end >= intervals[i].start) i++;
    newInterval.end = ((i == 0) ? newInterval.end:max(intervals[i - 1].end, newInterval.end));
    res.push_back(newInterval);
    while (i < n&&newInterval.end < intervals[i].start) res.push_back(intervals[i++]);
    return res;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用\[1\]和\[2\]中提到的错误是由于使用PyInstaller打包时出现的问题。这些错误可能是由于PyInstaller无法正确处理某些特定的Python模块或库导致的。解决这些错误的方法可能是更新PyInstaller版本,或者尝试使用其他打包工具。 至于引用\[3\]中提到的错误,即"'pandas._libs.interval.Interval' object has no attribute 'total_iv'",这个错误是由于在代码中使用了pandas._libs.interval.Interval对象的total_iv属性,但该属性在该对象中并不存在。这可能是由于使用了错误的属性名称或者版本不兼容导致的。要解决这个错误,您可以检查代码中对该属性的使用,并确保使用正确的属性名称。如果您使用的是较旧的pandas版本,可能需要升级到较新的版本以获得所需的属性。 总结起来,要解决这些错误,您可以尝试以下几个步骤: 1. 更新PyInstaller版本或尝试其他打包工具。 2. 检查代码中对属性的使用,并确保使用正确的属性名称。 3. 如果使用的是较旧的pandas版本,考虑升级到较新的版本以获得所需的属性。 希望这些解决方案能帮助您解决问题! #### 引用[.reference_title] - *1* *2* [成功解决pyinstaller打包AttributeError:type object pandas._TSObject has no attribute _reduce_cython_](https://blog.csdn.net/qq_41185868/article/details/80601983)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [ModuleNotFoundError: No module named ‘pandas._libs’](https://blog.csdn.net/yangning7777777/article/details/120909561)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值