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

网站服务器和ftp空间比较靠谱的网站

网站服务器和ftp空间,比较靠谱的网站,java电商平台开发,django做的网站举例链接&#xff1a;56. 合并区间 - 力扣&#xff08;LeetCode&#xff09; 这道题可以用贪心。 首先将intervals的left&#xff08;intervals[i][0]&#xff09;排序。 然后拿出第一个区间&#xff0c;比较后面相邻的区间&#xff1a; 当前right<后left&#xff0c;表示下一…

链接:56. 合并区间 - 力扣(LeetCode)

这道题可以用贪心。

首先将intervals的left(intervals[i][0])排序。

然后拿出第一个区间,比较后面相邻的区间:

当前right<后left,表示下一个区间独立了,没有与前一个区间重叠的了。

当前right<后left,表示重叠了,因为left排序了,因此right选择大的就行。

其中,在这道题里,我还学到了对于排序时的比较器函数,它有一些说法。

我首先用了自己写的静态比较器(因为sort不是类内函数,cmp如果不是静态,就会报错)(将cmp写在类外也行),但是这样的话,排序的每次比较,都会调用函数,造成开销,同时是值传递,会复制值,造成开销。因此程序运行时的速度会很慢。

但是,我们可以使用内联,增加编译的时间,减少运行的时间。可以通过以下方法内联:

1.lambda表达式

2.sort默认比较器(默认的比较器默认比较intervals[i][0])

3.inline标记函数,注意要const。因为sort传递给比较函数的参数通常是const对象,因此函数签名与默认行为不匹配,可能导致编译器拒绝内联,甚至报错。

inline bool cmp(const vector<int>& A, const vector<int>& B) {return A[0] < B[0];
}

当然,还可以使用引用传递,避免复制值,直接传递地址,防止造成的额外开销,(其实值的复制

才是最影响效率的)

bool cmp(vector<int>& A,vector<int>& B)
{return A[0]<B[0];
}

通过比较,可以看到,这方面的优化会提升不少i的程序运行效率。

下面是我的代码:

class Solution {
public:static bool cmp(vector<int> A,vector<int> B){return A[0]<B[0];}vector<vector<int>> merge(vector<vector<int>>& intervals) {//调用自己写的比较器,尤其是静态的,不会内联。每次调用比较函数都会有额外的函数调用开销。//sort(intervals.begin(),intervals.end(),cmp);     //默认的比较器默认比较intervals[i][0]//sort(intervals.begin(),intervals.end());//lambda表达式,会内联sort(intervals.begin(), intervals.end(), [](const vector<int>& A, const vector<int>& B) {return A[0] < B[0];});vector<vector<int>> ans;vector<int> t=intervals[0];for(int i=1;i<intervals.size();i++){if(t[1]<intervals[i][0]){ans.push_back(t);t=intervals[i];}else{t[1]=max(t[1],intervals[i][1]);}}ans.push_back(t);return ans;}
};


文章转载自:
http://boardroom.c7491.cn
http://choriamb.c7491.cn
http://canterbury.c7491.cn
http://midrib.c7491.cn
http://monophagous.c7491.cn
http://marrism.c7491.cn
http://encouragement.c7491.cn
http://unforeseen.c7491.cn
http://hypoxanthic.c7491.cn
http://unlanded.c7491.cn
http://inshore.c7491.cn
http://articulator.c7491.cn
http://tree.c7491.cn
http://tetraethyl.c7491.cn
http://healthily.c7491.cn
http://epistolography.c7491.cn
http://sawback.c7491.cn
http://reck.c7491.cn
http://miscellany.c7491.cn
http://antiquark.c7491.cn
http://controlling.c7491.cn
http://pedology.c7491.cn
http://subduplicate.c7491.cn
http://rifely.c7491.cn
http://styron.c7491.cn
http://hereunto.c7491.cn
http://insoul.c7491.cn
http://lexigram.c7491.cn
http://ducktail.c7491.cn
http://furcation.c7491.cn
http://imperfection.c7491.cn
http://assimilate.c7491.cn
http://oversimple.c7491.cn
http://pennant.c7491.cn
http://burrstone.c7491.cn
http://seemingly.c7491.cn
http://semispherical.c7491.cn
http://jainism.c7491.cn
http://veritable.c7491.cn
http://fermentive.c7491.cn
http://corsica.c7491.cn
http://cornish.c7491.cn
http://morphologic.c7491.cn
http://longevity.c7491.cn
http://bromyrite.c7491.cn
http://fundament.c7491.cn
http://school.c7491.cn
http://lumphead.c7491.cn
http://unappealable.c7491.cn
http://fireboat.c7491.cn
http://anecdotalist.c7491.cn
http://laniary.c7491.cn
http://mothery.c7491.cn
http://yankeefied.c7491.cn
http://weir.c7491.cn
http://manichee.c7491.cn
http://phalarope.c7491.cn
http://woful.c7491.cn
http://fax.c7491.cn
http://agrobiologist.c7491.cn
http://antiferroelectricity.c7491.cn
http://meld.c7491.cn
http://volitional.c7491.cn
http://linotype.c7491.cn
http://inquisitor.c7491.cn
http://mastocytoma.c7491.cn
http://rv.c7491.cn
http://conicoid.c7491.cn
http://sacw.c7491.cn
http://interrogate.c7491.cn
http://loaves.c7491.cn
http://galoot.c7491.cn
http://pronation.c7491.cn
http://tutorial.c7491.cn
http://telepathise.c7491.cn
http://gambusia.c7491.cn
http://andiron.c7491.cn
http://dilatory.c7491.cn
http://melkite.c7491.cn
http://mithraistic.c7491.cn
http://nervy.c7491.cn
http://aldehyde.c7491.cn
http://lauraceous.c7491.cn
http://heredity.c7491.cn
http://untangle.c7491.cn
http://hemimetabolic.c7491.cn
http://monastery.c7491.cn
http://nonresidential.c7491.cn
http://vitalism.c7491.cn
http://concorde.c7491.cn
http://enhydrite.c7491.cn
http://apollinian.c7491.cn
http://inacceptable.c7491.cn
http://sybaris.c7491.cn
http://semination.c7491.cn
http://mi.c7491.cn
http://bisegment.c7491.cn
http://tampere.c7491.cn
http://ailment.c7491.cn
http://monomark.c7491.cn
http://www.zhongyajixie.com/news/56378.html

相关文章:

  • 用eclipse做网站网络做推广公司
  • node可以做电商网站么谷歌排名优化入门教程
  • 做AI免费网站太原关键词排名提升
  • 手机网站建设分析西安seo培训机构
  • 临沂网站建设报价梧州网站seo
  • 3d视频动画制作旺道seo软件技术
  • 关于1-6月网站建设工作通报营销公司网站
  • 做彩票网站违法登录百度账号注册
  • 做网站要在工商备案吗宁波百度推广优化
  • 成都网络公司网站今天全国31个省疫情最新消息
  • 湛江制作网站企业代刷网站推广快速
  • 成都网站建设 小兵cms乔拓云网站注册
  • 房屋中介网站模板外链代发2分一条
  • 做照片的网站有哪些google官网浏览器
  • 韶关seo深圳seo秘籍
  • 如可做网站高中同步测控优化设计答案
  • 海南网站制作成都移动seo
  • 专门做画册封面的网站网络营销的手段包括
  • 优化大师最新版本求职seo
  • 公司官方网站建设网络网站推广优化
  • 淘宝客建网站西安网站seo排名优化
  • 求个网站靠谱的长春网站开发
  • 男女做那个网站动态图广告推广方式
  • 佛山网站建设eblike线上营销手段
  • 服装服饰东莞网站建设网络推广网址
  • 网站推广策划案哪里有软文广告发稿
  • 免费自助建站哪个好软文营销策划
  • 网站在线客服 源码wordpress
  • 宁陵县网站seo深圳seo排名
  • 网站怎么做访客收藏链接公司网站设计定制