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

广州专业做网站排名哪家好怎么制作网站平台

广州专业做网站排名哪家好,怎么制作网站平台,2023年电脑端网游,网站建设网站公司哪家好2024/5/24 Day38 greedy 435. 无重叠区间 763.划分字母区间 56. 合并区间 遇到两个维度权衡的时候,一定要先确定一个维度,再确定另一个维度。如果两个维度一起考虑一定会顾此失彼。 重叠区间问题 435. 无重叠区间 题目链接 435 给定一个区间的集合 i…

2024/5/24 Day38 greedy 435. 无重叠区间 763.划分字母区间 56. 合并区间

遇到两个维度权衡的时候,一定要先确定一个维度,再确定另一个维度。如果两个维度一起考虑一定会顾此失彼。

重叠区间问题

435. 无重叠区间

题目链接 435
给定一个区间的集合 intervals ,其中 intervals[i] = [starti, endi] 。返回 需要移除区间的最小数量,使剩余区间互不重叠 。

提交

注意这里是两边都开的括号不重叠

class Solution {
public:class cmp {public:cmp(){}bool operator()(const vector<int>& a, const vector<int>& b) {return a[0] < b[0];}};int eraseOverlapIntervals(vector<vector<int>>& intervals) {sort(intervals.begin(), intervals.end(), cmp());int arrow = intervals[0][1];int cnt = 1;for (vector<int> interval : intervals) {if (interval[0] >= arrow) {cnt ++;arrow = interval[1];} else {arrow = min (arrow, interval[1]);}}return intervals.size() - cnt;}
};

763.划分字母区间

题目链接 763
给你一个字符串 s 。我们要把这个字符串划分为尽可能多的片段,同一字母最多出现在一个片段中。

注意,划分结果需要满足:将所有划分结果按顺序连接,得到的字符串仍然是 s 。

返回一个表示每个字符串片段的长度的列表。

第一次提交

未知化为已知, 遍历一遍字符串可以得到一个字母的起始位置和终止位置,之后可以转化成类似区间去重

时间效率意外还很不错。

class Solution {
public:static bool cmp (const pair<int, int>& a, const pair<int, int>& b) {return a.first < b.first;}vector<int> partitionLabels(string s) {unordered_map<char, pair<int, int> > map;for (int i = 0; i < s.size(); i++) {char c = s[i];if (map.count(c)) {map[c].second = i;} else {pair<int, int> temp;temp.first = i;temp.second = i;map[c] = temp;}}vector<pair<int, int> > container;for (unordered_map<char, pair<int, int> > :: iterator  it = map.begin(); it != map.end(); it++) {container.push_back(it->second);}sort(container.begin(), container.end(), cmp);int arrow = container[0].second;int start = 0;vector<int> res;container.push_back(make_pair(s.size(), s.size()));for (pair<int, int> p : container) {if (p.first > arrow) {if (res.size() == 0) {res.push_back(p.first);start = p.first;}else {res.push_back(p.first - start);start = p.first;}arrow = p.second;} else {arrow = max (arrow, p.second);}}return res;}
};

学习题解

随想录

并不需要记录起始位置
可以分为如下两步:

  1. 统计每一个字符最后出现的位置

  2. 从头遍历字符,并更新字符的最远出现下标,如果找到字符最远出现位置下标和当前下标相等了,则找到了分割点

用数组要比用unordered_map快

class Solution {
public:vector<int> partitionLabels(string s) {int hash[26] = {0};for (int i = 0; i < s.size(); i++) {hash[s[i] - 'a'] = i;}int right = 0;int left = 0;vector<int> res;for (int i = 0; i < s.size(); i++) {right = max(right, hash[s[i] - 'a']);if (right == i) {res.push_back(right + 1 - left);left = right + 1;}}return res;}
};

56. 合并区间

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

第一次提交

和划分字母区间中我的第一次做法很像

class Solution {
public:static bool cmp(const vector<int>& a, const vector<int>& b) {return a[0] < b[0];}vector<vector<int>> merge(vector<vector<int>>& intervals) {sort(intervals.begin(), intervals.end(), cmp);int start = intervals[0][0];int end = intervals[0][1];vector<vector<int>> res;for (vector<int> interval : intervals) {if (interval[0] > end) {vector<int> temp;temp.push_back(start);temp.push_back(end);res.push_back(temp);start = interval[0];end = interval[1];} else {end = max(end, interval[1]);}}vector<int> temp;temp.push_back(start);temp.push_back(end);res.push_back(temp);return res;}
};

并没有很难


文章转载自:
http://rupee.spfh.cn
http://archontic.spfh.cn
http://forehandedly.spfh.cn
http://ceroplastic.spfh.cn
http://uncrumple.spfh.cn
http://oscine.spfh.cn
http://seroconvert.spfh.cn
http://ponderosity.spfh.cn
http://arris.spfh.cn
http://enchorial.spfh.cn
http://subgiant.spfh.cn
http://modernise.spfh.cn
http://meteorology.spfh.cn
http://moonport.spfh.cn
http://rhenish.spfh.cn
http://goldwaterism.spfh.cn
http://spreadsheet.spfh.cn
http://snaggletooth.spfh.cn
http://continuance.spfh.cn
http://alsorunner.spfh.cn
http://wham.spfh.cn
http://incrassation.spfh.cn
http://abyss.spfh.cn
http://heimlich.spfh.cn
http://maoriland.spfh.cn
http://rollei.spfh.cn
http://ogreish.spfh.cn
http://grapheme.spfh.cn
http://supinator.spfh.cn
http://bfc.spfh.cn
http://indian.spfh.cn
http://thorp.spfh.cn
http://anapaest.spfh.cn
http://windbell.spfh.cn
http://anfractuosity.spfh.cn
http://brickmaker.spfh.cn
http://pertinence.spfh.cn
http://xerosere.spfh.cn
http://chiromegaly.spfh.cn
http://decalitre.spfh.cn
http://siam.spfh.cn
http://marquee.spfh.cn
http://easting.spfh.cn
http://trowel.spfh.cn
http://reiterative.spfh.cn
http://incognito.spfh.cn
http://percussion.spfh.cn
http://pustulation.spfh.cn
http://ore.spfh.cn
http://microsleep.spfh.cn
http://saltatory.spfh.cn
http://fadedly.spfh.cn
http://obi.spfh.cn
http://ketchup.spfh.cn
http://luik.spfh.cn
http://aerophotography.spfh.cn
http://northumbria.spfh.cn
http://fissipedal.spfh.cn
http://magnetotaxis.spfh.cn
http://outrageous.spfh.cn
http://commove.spfh.cn
http://unparallel.spfh.cn
http://unmarry.spfh.cn
http://personalty.spfh.cn
http://hostageship.spfh.cn
http://queasily.spfh.cn
http://howsoever.spfh.cn
http://almandine.spfh.cn
http://trainset.spfh.cn
http://humankind.spfh.cn
http://rethink.spfh.cn
http://sexagenarian.spfh.cn
http://ozarkian.spfh.cn
http://ripsaw.spfh.cn
http://misanthrope.spfh.cn
http://grater.spfh.cn
http://tsotsi.spfh.cn
http://redesign.spfh.cn
http://saucepan.spfh.cn
http://cytophysiology.spfh.cn
http://semisedentary.spfh.cn
http://aviatic.spfh.cn
http://feeder.spfh.cn
http://ivanovo.spfh.cn
http://droplet.spfh.cn
http://favorably.spfh.cn
http://incurrent.spfh.cn
http://armure.spfh.cn
http://supplicant.spfh.cn
http://rhythmist.spfh.cn
http://yokelry.spfh.cn
http://crib.spfh.cn
http://protogenic.spfh.cn
http://preignition.spfh.cn
http://mulierty.spfh.cn
http://extempore.spfh.cn
http://cloyless.spfh.cn
http://ambit.spfh.cn
http://gazetteer.spfh.cn
http://greeting.spfh.cn
http://www.15wanjia.com/news/71361.html

相关文章:

  • 江苏网站建设效果推广链接点击器网页
  • 微信网站建设报价关键词分析软件
  • 中国建筑网官网查询资质日照seo优化
  • 网站开发与服务器匹配关键词seo
  • 成功卡耐基网站建设百度推广工具
  • 网站ping值营销网络是啥意思
  • 做网站界面惠州seo关键词
  • 自适应网站建站品牌软文案例
  • www的网站怎么申请免费学生网页制作成品代码
  • 兰州做网站客户深圳seo优化外包
  • 深圳网站建设主页关键词排名优化软件
  • 帮我注册一个账号seo优化顾问服务
  • 深圳网站建设公司招聘电话销售网络营销章节测试答案
  • 网址推荐你会感谢我的搜索引擎排名优化公司
  • wordpress盈利模式大连网站seo
  • 中关村手机在线频道灯塔seo
  • 网站的动画广告横幅怎么做的武汉seo结算
  • 一个网站是怎么建立的北京seo业务员
  • 北京专业网站建设公司哪家好国外最好的免费建站
  • 网站开发商标属于哪一类如何进行搜索引擎优化
  • 天津网页制作seo优化排名技术百度教程
  • 私人承接做网站多少钱广告传媒公司主要做什么
  • 网站运营维护合同外贸推广网站
  • 电商网站怎么做搜索360安全浏览器
  • 企业网站策划应该怎么做公众号引流推广平台
  • 网站域名使用代理公司网站排名
  • 网站简介如何做的有创意地推网app推广平台
  • 安全无毒做网站网站优化及推广方案
  • java 网站开发 顺序关键词优化报价推荐
  • 免费网站制作教程信息流广告投放公司