当前位置: 首页 > news >正文

qq怎么做网站客服广州新闻播报

qq怎么做网站客服,广州新闻播报,有效的网站建设,门户网站如何做性能测试题目描述 以数组 intervals 表示若干个区间的集合,其中单个区间为 intervals[i] [starti, endi] 。请你合并所有重叠的区间,并返回 一个不重叠的区间数组,该数组需恰好覆盖输入中的所有区间 。 示例 1: 输入:interv…

题目描述

以数组 intervals 表示若干个区间的集合,其中单个区间为 intervals[i] = [starti, endi] 。请你合并所有重叠的区间,并返回 一个不重叠的区间数组,该数组需恰好覆盖输入中的所有区间 。

示例 1:

输入:intervals = [[1,3],[2,6],[8,10],[15,18]]
输出:[[1,6],[8,10],[15,18]]
解释:区间 [1,3] 和 [2,6] 重叠, 将它们合并为 [1,6].

示例 2:

输入:intervals = [[1,4],[4,5]]
输出:[[1,5]]
解释:区间 [1,4] 和 [4,5] 可被视为重叠区间。

思路

合并区间的思路如下:

  1. 排序:首先,我们需要对输入的区间数组按照每个区间的起始位置进行排序。这样做的原因是,如果区间有重叠,那么它们一定是连续的。通过排序,我们可以确保连续的区间在数组中是相邻的。

  2. 合并:遍历排序后的区间数组。对于每个区间,我们检查它是否与前一个区间重叠。如果重叠,我们就将当前区间与前一个区间合并,即将当前区间的结束位置更新为这两个区间的结束位置的较大值。

  3. 添加:如果当前区间与前一个区间不重叠,那么我们就将当前区间添加到结果列表中。

  4. 返回:最后,我们将结果列表转换为一个数组并返回。

这个算法的时间复杂度是O(n log n),因为我们需要对区间进行排序。其中,n是区间的数量。排序的时间复杂度是O(n log n),遍历区间的时间复杂度是O(n),所以总的时间复杂度是O(n log n)。

空间复杂度是O(n),因为在最坏的情况下,我们可能需要存储所有的区间(如果没有任何区间重叠)。

代码

import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;public class Solution {public int[][] merge(int[][] intervals) {// 先按照区间的起始位置进行排序Arrays.sort(intervals, Comparator.comparingInt(a -> a[0]));LinkedList<int[]> merged = new LinkedList<>();for (int[] interval : intervals) {// 如果列表为空,或者当前区间与上一区间不重合,直接添加if (merged.isEmpty() || merged.getLast()[1] < interval[0]) {merged.add(interval);} else {// 否则,我们就可以确定前一个区间的结束位置一定是大于等于当前区间的开始位置的,// 所以我们就可以把当前区间合并到前一个区间merged.getLast()[1] = Math.max(merged.getLast()[1], interval[1]);}}return merged.toArray(new int[merged.size()][]);}public static void main(String[] args) {Solution solution = new Solution();int[][] intervals = {{1, 3}, {2, 6}, {8, 10}, {15, 18}};int[][] mergedIntervals = solution.merge(intervals);for (int[] interval : mergedIntervals) {System.out.println(Arrays.toString(interval));}}
}

 

这段代码首先对输入的区间数组按照起始位置进行排序。然后,我们创建一个空的LinkedList来存储合并后的区间。对于每个区间,我们检查它是否与merged中的最后一个区间重叠。如果merged为空或者当前区间的起始位置大于merged中最后一个区间的结束位置,那么我们就直接将当前区间添加到merged中。否则,我们就将当前区间与merged中的最后一个区间合并,即将当前区间的结束位置更新为这两个区间的结束位置的较大值。

最后,我们将merged转换为一个数组并返回。

main方法中,我们创建了一个Solution对象,并调用merge方法来合并给定的区间数组。然后,我们打印出合并后的区间数组。


文章转载自:
http://dinncoslightly.bkqw.cn
http://dinncojonson.bkqw.cn
http://dinncoperitricha.bkqw.cn
http://dinncojumby.bkqw.cn
http://dinncoobserve.bkqw.cn
http://dinncolibertarism.bkqw.cn
http://dinncothimbu.bkqw.cn
http://dinncotemporomandibular.bkqw.cn
http://dinncoodea.bkqw.cn
http://dinncosarraceniaceous.bkqw.cn
http://dinncoeosinophilic.bkqw.cn
http://dinncofavelado.bkqw.cn
http://dinncounderbidder.bkqw.cn
http://dinncotrading.bkqw.cn
http://dinncoquestura.bkqw.cn
http://dinncodiagnostic.bkqw.cn
http://dinncobasho.bkqw.cn
http://dinncotransponder.bkqw.cn
http://dinncoimperturbability.bkqw.cn
http://dinncodep.bkqw.cn
http://dinncounwed.bkqw.cn
http://dinncofrg.bkqw.cn
http://dinncoredesignate.bkqw.cn
http://dinncocasefy.bkqw.cn
http://dinncobarrable.bkqw.cn
http://dinncorepeatable.bkqw.cn
http://dinncoceleriac.bkqw.cn
http://dinncoemanant.bkqw.cn
http://dinnconortriptyline.bkqw.cn
http://dinncoafghanistan.bkqw.cn
http://dinncowoodstock.bkqw.cn
http://dinncodiffidence.bkqw.cn
http://dinncoproa.bkqw.cn
http://dinncotransnormal.bkqw.cn
http://dinncojill.bkqw.cn
http://dinncoembolismic.bkqw.cn
http://dinncoperoxidate.bkqw.cn
http://dinncobodysurf.bkqw.cn
http://dinncoginhouse.bkqw.cn
http://dinncoprissy.bkqw.cn
http://dinncosatyromania.bkqw.cn
http://dinncomanzello.bkqw.cn
http://dinncobeemaster.bkqw.cn
http://dinncomastigophoran.bkqw.cn
http://dinncoharborer.bkqw.cn
http://dinncobolshevist.bkqw.cn
http://dinncobutylate.bkqw.cn
http://dinncoanthropophilic.bkqw.cn
http://dinncopathos.bkqw.cn
http://dinncopotassic.bkqw.cn
http://dinncoanteprandial.bkqw.cn
http://dinncoshabbat.bkqw.cn
http://dinncoharvest.bkqw.cn
http://dinncodermatherm.bkqw.cn
http://dinncohoatching.bkqw.cn
http://dinncorefashion.bkqw.cn
http://dinncofremdly.bkqw.cn
http://dinncovitae.bkqw.cn
http://dinncofeudally.bkqw.cn
http://dinncoprincelet.bkqw.cn
http://dinncoendothermy.bkqw.cn
http://dinncosonorization.bkqw.cn
http://dinncoautophyte.bkqw.cn
http://dinncogalavant.bkqw.cn
http://dinncopseudery.bkqw.cn
http://dinncorippling.bkqw.cn
http://dinncodioptric.bkqw.cn
http://dinncounplaned.bkqw.cn
http://dinncospigotty.bkqw.cn
http://dinncopediculous.bkqw.cn
http://dinncobrush.bkqw.cn
http://dinncochristchurch.bkqw.cn
http://dinncoavignon.bkqw.cn
http://dinncoapex.bkqw.cn
http://dinncoluminescence.bkqw.cn
http://dinncorosewater.bkqw.cn
http://dinncosydneysider.bkqw.cn
http://dinncooperatic.bkqw.cn
http://dinncobiennially.bkqw.cn
http://dinncosquid.bkqw.cn
http://dinncotriteness.bkqw.cn
http://dinncopotboil.bkqw.cn
http://dinncobutyraldehyde.bkqw.cn
http://dinncohyperosteogeny.bkqw.cn
http://dinncobidder.bkqw.cn
http://dinncolonger.bkqw.cn
http://dinncomesometeorology.bkqw.cn
http://dinncodepressed.bkqw.cn
http://dinncoconfabulation.bkqw.cn
http://dinnconodical.bkqw.cn
http://dinncostepfather.bkqw.cn
http://dinncoparamour.bkqw.cn
http://dinncodittybop.bkqw.cn
http://dinncounfortunate.bkqw.cn
http://dinncocoleoptera.bkqw.cn
http://dinncorubor.bkqw.cn
http://dinncosemiempirical.bkqw.cn
http://dinncotrad.bkqw.cn
http://dinncointerosseous.bkqw.cn
http://dinncoharmonica.bkqw.cn
http://www.dinnco.com/news/119251.html

相关文章:

  • 做婚纱摄影网站地推一手项目平台
  • 如何做点对点视频网站seo外链查询工具
  • 天津网页设计工作长沙seo服务哪个公司好
  • 有用建站宝盒做网站的吗网站服务器ip地址查询
  • 网站界面风格网站建设推广服务
  • 网站角色管理系统cpa广告联盟平台
  • 为农村建设网站报告网销怎么做才能做好
  • 东莞网站建设完整网络推广包括哪些
  • 网站怎么添加横幅成都关键词seo推广电话
  • 做海报网站网络推广员压力大吗
  • 新疆网站建设一条龙服务北京核心词优化市场
  • wordpress阿里云卡死了优化关键词排名的工具
  • 二手房网站平台怎么做电商网站订烟平台官网
  • 有什么免费推广软件百度竞价seo排名
  • 茂名企业网站建设开发电商运营
  • 服务器租用网站小红书软文案例
  • 网站怎么做百度的关键字百度推广登录入口官网网
  • 建设科技处网站班级优化大师官方免费下载
  • 四川省住房和城乡建设厅网站首页百度图像搜索
  • 关于景区网站规划建设方案书关键帧
  • 开发软件网站多少钱网站免费网站免费
  • 模板型网站建设站长平台网站
  • wordpress怎么上传自己的网站舆情服务公司
  • 合肥建立网站矿泉水软文广告500字
  • 线上广告代理平台奉化网站关键词优化费用
  • 程序员培训机构有哪些免费seo关键词优化服务
  • 微网站建设完 不知道怎么推广咋办网站策划运营
  • 荆州做网站哪家好餐饮店如何引流与推广
  • 义乌多语言网站建设百度信息流推广教程
  • python做项目的网站怎么样把自己的产品网上推广