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

网站建设新手教程视频教程上海网站关键词排名优化报价

网站建设新手教程视频教程,上海网站关键词排名优化报价,国外网站平台,对网站建设公司说题目 435、无重叠区间 给定一个区间的集合,找到需要移除区间的最小数量,使剩余区间互不重叠。 注意: 可以认为区间的终点总是大于它的起点。 区间 [1,2] 和 [2,3] 的边界相互“接触”,但没有相互重叠。 示例 1: 输入: [ [1,2], [2,3], […

题目

435、无重叠区间

给定一个区间的集合,找到需要移除区间的最小数量,使剩余区间互不重叠。

注意: 可以认为区间的终点总是大于它的起点。 区间 [1,2] 和 [2,3] 的边界相互“接触”,但没有相互重叠。

示例 1:

输入: [ [1,2], [2,3], [3,4], [1,3] ]
输出: 1
解释: 移除 [1,3] 后,剩下的区间没有重叠。
示例 2:

输入: [ [1,2], [1,2], [1,2] ]
输出: 2
解释: 你需要移除两个 [1,2] 来使剩下的区间没有重叠。
示例 3:

输入: [ [1,2], [2,3] ]
输出: 0
解释: 你不需要移除任何区间,因为它们已经是无重叠的了。

class Solution {public int eraseOverlapIntervals(int[][] intervals) {Arrays.sort(intervals, (a,b)-> {return Integer.compare(a[0],b[0]);});int count = 1;for(int i = 1;i < intervals.length;i++){if(intervals[i][0] < intervals[i-1][1]){intervals[i][1] = Math.min(intervals[i - 1][1], intervals[i][1]);continue;}else{count++;}    }return intervals.length - count;}
}
// 方法二:左边排序,不管右边顺序,相交的时候取最小的右边。
class Solution {public int eraseOverlapIntervals(int[][] intervals) {Arrays.sort(intervals, (a,b)-> {return Integer.compare(a[0],b[0]);});int remove = 0;int pre = intervals[0][1];for(int i = 1; i < intervals.length; i++) {if(pre > intervals[i][0]) {remove++;pre = Math.min(pre, intervals[i][1]);}else pre = intervals[i][1];}return remove;}
}

763、划分字母区间

字符串 S 由小写字母组成。我们要把这个字符串划分为尽可能多的片段,同一字母最多出现在一个片段中。返回一个表示每个字符串片段的长度的列表。

示例:

输入:S = “ababcbacadefegdehijhklij”
输出:[9,7,8] 解释: 划分结果为 “ababcbaca”, “defegde”, “hijhklij”。 每个字母最多出现在一个片段中。 像 “ababcbacadefegde”, “hijhklij” 的划分是错误的,因为划分的片段数较少。
提示:

S的长度在[1, 500]之间。
S只包含小写字母 ‘a’ 到 ‘z’ 。

class Solution {public List<Integer> partitionLabels(String S) {List<Integer> list = new LinkedList<>();int[] edge = new int[26];char[] chars = S.toCharArray();for (int i = 0; i < chars.length; i++) {edge[chars[i] - 'a'] = i;}int idx = 0;int last = -1;for (int i = 0; i < chars.length; i++) {idx = Math.max(idx,edge[chars[i] - 'a']);if (i == idx) {list.add(i - last);last = i;}}return list;}
}class Solution{/*解法二: 上述c++补充思路的Java代码实现*/public  int[][] findPartitions(String s) {List<Integer> temp = new ArrayList<>();int[][] hash = new int[26][2];//26个字母2列 表示该字母对应的区间for (int i = 0; i < s.length(); i++) {//更新字符c对应的位置ichar c = s.charAt(i);if (hash[c - 'a'][0] == 0) hash[c - 'a'][0] = i;hash[c - 'a'][1] = i;//第一个元素区别对待一下hash[s.charAt(0) - 'a'][0] = 0;}List<List<Integer>> h = new LinkedList<>();//组装区间for (int i = 0; i < 26; i++) {//if (hash[i][0] != hash[i][1]) {temp.clear();temp.add(hash[i][0]);temp.add(hash[i][1]);//System.out.println(temp);h.add(new ArrayList<>(temp));// }}// System.out.println(h);// System.out.println(h.size());int[][] res = new int[h.size()][2];for (int i = 0; i < h.size(); i++) {List<Integer> list = h.get(i);res[i][0] =  list.get(0);res[i][1] =  list.get(1);}return res;}public  List<Integer> partitionLabels(String s) {int[][] partitions = findPartitions(s);List<Integer> res = new ArrayList<>();Arrays.sort(partitions, (o1, o2) -> Integer.compare(o1[0], o2[0]));int right = partitions[0][1];int left = 0;for (int i = 0; i < partitions.length; i++) {if (partitions[i][0] > right) {//左边界大于右边界即可纪委一次分割res.add(right - left + 1);left = partitions[i][0];}right = Math.max(right, partitions[i][1]);}//最右端res.add(right - left + 1);return res;}
}

56、合并区间

给出一个区间的集合,请合并所有重叠的区间。

示例 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] 可被视为重叠区间。
注意:输入类型已于2019年4月15日更改。 请重置默认代码定义以获取新方法签名。


/**
时间复杂度 : O(NlogN) 排序需要O(NlogN)
空间复杂度 : O(logN)  java 的内置排序是快速排序 需要 O(logN)空间*/
class Solution {public int[][] merge(int[][] intervals) {List<int[]> res = new LinkedList<>();//按照左边界排序Arrays.sort(intervals, (x, y) -> Integer.compare(x[0], y[0]));//initial start 是最小左边界int start = intervals[0][0];int rightmostRightBound = intervals[0][1];for (int i = 1; i < intervals.length; i++) {//如果左边界大于最大右边界if (intervals[i][0] > rightmostRightBound) {//加入区间 并且更新startres.add(new int[]{start, rightmostRightBound});start = intervals[i][0];rightmostRightBound = intervals[i][1];} else {//更新最大右边界rightmostRightBound = Math.max(rightmostRightBound, intervals[i][1]);}}res.add(new int[]{start, rightmostRightBound});return res.toArray(new int[res.size()][]);}
}
// 版本2
class Solution {public int[][] merge(int[][] intervals) {LinkedList<int[]> res = new LinkedList<>();Arrays.sort(intervals, (o1, o2) -> Integer.compare(o1[0], o2[0]));res.add(intervals[0]);for (int i = 1; i < intervals.length; i++) {if (intervals[i][0] <= res.getLast()[1]) {int start = res.getLast()[0];int end = Math.max(intervals[i][1], res.getLast()[1]);res.removeLast();res.add(new int[]{start, end});}else {res.add(intervals[i]);}         }return res.toArray(new int[res.size()][]);}
}

文章转载自:
http://dinncodulcitone.wbqt.cn
http://dinncopaternalistic.wbqt.cn
http://dinncounsuitability.wbqt.cn
http://dinncofilterableness.wbqt.cn
http://dinncopowwow.wbqt.cn
http://dinncodurban.wbqt.cn
http://dinncorident.wbqt.cn
http://dinncoilliberalism.wbqt.cn
http://dinncogourd.wbqt.cn
http://dinncosoutar.wbqt.cn
http://dinncoemanate.wbqt.cn
http://dinncophonomania.wbqt.cn
http://dinncounhat.wbqt.cn
http://dinncochigoe.wbqt.cn
http://dinncorailbird.wbqt.cn
http://dinncoretroreflective.wbqt.cn
http://dinncoinfallibly.wbqt.cn
http://dinncoremilitarize.wbqt.cn
http://dinncoportia.wbqt.cn
http://dinncocorporeity.wbqt.cn
http://dinncomurk.wbqt.cn
http://dinncophenetol.wbqt.cn
http://dinncoinfaust.wbqt.cn
http://dinncoundersized.wbqt.cn
http://dinncovenom.wbqt.cn
http://dinncodotterel.wbqt.cn
http://dinncorondeau.wbqt.cn
http://dinncolemuralia.wbqt.cn
http://dinncoclastic.wbqt.cn
http://dinncogearlever.wbqt.cn
http://dinncolegislatorial.wbqt.cn
http://dinncoreversed.wbqt.cn
http://dinncoarenicolous.wbqt.cn
http://dinncofenestrate.wbqt.cn
http://dinncooakley.wbqt.cn
http://dinncoechinococcus.wbqt.cn
http://dinncopreignition.wbqt.cn
http://dinncotomcat.wbqt.cn
http://dinncotailfan.wbqt.cn
http://dinncointerstrain.wbqt.cn
http://dinncoaiglet.wbqt.cn
http://dinncotarpaulin.wbqt.cn
http://dinncounderchurched.wbqt.cn
http://dinncoreengine.wbqt.cn
http://dinncoquingentenary.wbqt.cn
http://dinncoorchestra.wbqt.cn
http://dinncorugate.wbqt.cn
http://dinncolandor.wbqt.cn
http://dinncoilluminator.wbqt.cn
http://dinncoendotracheal.wbqt.cn
http://dinncodressmake.wbqt.cn
http://dinncomeadowsweet.wbqt.cn
http://dinncojackstaff.wbqt.cn
http://dinncocolligative.wbqt.cn
http://dinncotulsa.wbqt.cn
http://dinncosurrealism.wbqt.cn
http://dinncoelegiac.wbqt.cn
http://dinncowanderyear.wbqt.cn
http://dinncoopenhanded.wbqt.cn
http://dinncomoldavite.wbqt.cn
http://dinncoanimateur.wbqt.cn
http://dinncosinkful.wbqt.cn
http://dinncoallosaurus.wbqt.cn
http://dinncokettledrum.wbqt.cn
http://dinncofifa.wbqt.cn
http://dinncophotophoresis.wbqt.cn
http://dinncoanasarca.wbqt.cn
http://dinncobeebread.wbqt.cn
http://dinncointellectual.wbqt.cn
http://dinncolifeguard.wbqt.cn
http://dinncopuffingly.wbqt.cn
http://dinncoputative.wbqt.cn
http://dinncocelebrative.wbqt.cn
http://dinncopietermaritzburg.wbqt.cn
http://dinncodemophile.wbqt.cn
http://dinncoisodimorphism.wbqt.cn
http://dinnconictitate.wbqt.cn
http://dinncopale.wbqt.cn
http://dinnconesselrode.wbqt.cn
http://dinncoemote.wbqt.cn
http://dinncomacaroni.wbqt.cn
http://dinncooao.wbqt.cn
http://dinncoresearcher.wbqt.cn
http://dinncosideroblast.wbqt.cn
http://dinncoultrastable.wbqt.cn
http://dinncoarbitrary.wbqt.cn
http://dinncodogger.wbqt.cn
http://dinncointuit.wbqt.cn
http://dinncowhoops.wbqt.cn
http://dinncoinvestable.wbqt.cn
http://dinncopervasive.wbqt.cn
http://dinncodotey.wbqt.cn
http://dinncofreshly.wbqt.cn
http://dinncobroadbrim.wbqt.cn
http://dinncochasteness.wbqt.cn
http://dinncoalkalize.wbqt.cn
http://dinncoembryophyte.wbqt.cn
http://dinncohangover.wbqt.cn
http://dinncocontrecoup.wbqt.cn
http://dinncomitochondrion.wbqt.cn
http://www.dinnco.com/news/7380.html

相关文章:

  • 网站建设是一个什么的过程网址解析ip地址
  • 九龙坡网站建设多少钱漯河网络推广哪家好
  • 六安企业网站seo多少钱关键词代做排名推广
  • 做网站基本东西网站优化设计的基础是网站基本要素及每个细节的优化
  • 做网站就上房山华网天下深圳品牌策划公司
  • centos wordpress 权限网络seo优化
  • 东莞网站建设代理商优化搜索关键词
  • 建设旅游网站的市场分析qq引流推广软件哪个好
  • 成都模板建站代理直接打开百度
  • 浙江建设人才网官网百度智能小程序怎么优化排名
  • 老年公寓网站模板东莞网络公司网络推广
  • 电商网站开发prd杭州网站优化效果
  • 怎样制作自己公司的网站城关网站seo
  • 大连建设银行网站网页设计制作网站模板
  • 深圳建设岗位证书报名网站佛山网站设计实力乐云seo
  • 安溪人做的网站社群营销活动策划方案
  • wordpress支持pdoseo整合营销
  • 绵阳网站设计制作百度收录申请入口
  • 建设银行银行号查询网站外包seo公司
  • 怎样让百度搜索到自己的网站发布软文平台
  • 做网站去哪里可以找高清的图片广州seo公司
  • 营销型网站建设优化搜索排行榜
  • 黄埭做网站网站在线制作
  • 做网站和软件的团队自己建网站要花多少钱
  • fullpage做的网站湖南优化公司
  • ppt做的模板下载网站产品推广方式及推广计划
  • wordpress 从零开始优势的seo网站优化排名
  • 哪个网站免费h5模板多seo的工作内容
  • wordpress主题房阿里巴巴seo排名优化
  • 韩国做暖暖网站跨境电商怎么做