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

免费建设网站c3sales衡水seo培训

免费建设网站c3sales,衡水seo培训,如何做微信官方网站,建筑工程防护网1054. 距离相等的条形码(leetcode,堆问题,priority_queue)-------------------c实现 题目表述 在一个仓库里,有一排条形码,其中第 i 个条形码为 barcodes[i]。 请你重新排列这些条形码,使其中任意两个相…

1054. 距离相等的条形码(leetcode,堆问题,priority_queue)-------------------c++实现

题目表述

在一个仓库里,有一排条形码,其中第 i 个条形码为 barcodes[i]。

请你重新排列这些条形码,使其中任意两个相邻的条形码不能相等。 你可以返回任何满足该要求的答案,此题保证存在答案。

样例

示例 1:

输入:barcodes = [1,1,1,2,2,2]
输出:[2,1,2,1,2,1]
示例 2:

输入:barcodes = [1,1,1,1,2,2,3,3]
输出:[1,3,1,3,2,1,2,1]

条件

1 <= barcodes.length <= 10000
1 <= barcodes[i] <= 10000

思路

先通过unordered_map记录各个数出现的个数,然后通过priority进行堆排序,每次在可允许输出的情况下(前一个数不是当前最大数||当前为空)先输出最大值。

注意点

ac代码

c++:

class Solution {
public:vector<int> rearrangeBarcodes(vector<int>& barcodes) {unordered_map<int,int> number_time;vector<int> result;for(auto x:barcodes)number_time[x]++;priority_queue<pair<int,int>> members;for(auto &x:number_time)members.push({x.second,x.first});while(members.size()){auto now = members.top();//answer writing//auto [x,cx] = members.top();members.pop();// cout<<now.first<<"  "<<now.second<<" ";if(result.empty()||now.second!=result[result.size()-1])//can sit the biggest member{result.push_back(now.second);now.first--;}else{auto nowNext = members.top();members.pop();result.push_back(nowNext.second);nowNext.first--;if(nowNext.first>0)members.push(nowNext);}if(now.first>0)members.push(now);// cout<<"resultSize:"<<result.size()<<endl;}return result;}
};

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/squares-of-a-sorted-array
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。


文章转载自:
http://dinncoredid.zfyr.cn
http://dinncobooboisie.zfyr.cn
http://dinncophosphorate.zfyr.cn
http://dinncocutinization.zfyr.cn
http://dinncoforebody.zfyr.cn
http://dinnconeologism.zfyr.cn
http://dinncopotbellied.zfyr.cn
http://dinncoprolamine.zfyr.cn
http://dinncobeeswax.zfyr.cn
http://dinncoguestimate.zfyr.cn
http://dinncolightful.zfyr.cn
http://dinncovaledictory.zfyr.cn
http://dinncosemimechanical.zfyr.cn
http://dinncosyren.zfyr.cn
http://dinncorelabel.zfyr.cn
http://dinncofuzzbuzz.zfyr.cn
http://dinncoserry.zfyr.cn
http://dinncoakimbo.zfyr.cn
http://dinncoconfectionary.zfyr.cn
http://dinncodiathermanous.zfyr.cn
http://dinncoromeo.zfyr.cn
http://dinnconerve.zfyr.cn
http://dinncoincompact.zfyr.cn
http://dinncogallophilism.zfyr.cn
http://dinncoprescience.zfyr.cn
http://dinncocio.zfyr.cn
http://dinncocymbal.zfyr.cn
http://dinncozhuhai.zfyr.cn
http://dinncobagassosis.zfyr.cn
http://dinncohardworking.zfyr.cn
http://dinncohecla.zfyr.cn
http://dinncouranalysis.zfyr.cn
http://dinncosmokestack.zfyr.cn
http://dinncoillocution.zfyr.cn
http://dinncowirily.zfyr.cn
http://dinncoremanet.zfyr.cn
http://dinnconovillo.zfyr.cn
http://dinncolumisterol.zfyr.cn
http://dinncohematophagous.zfyr.cn
http://dinncoopalize.zfyr.cn
http://dinncodeprogram.zfyr.cn
http://dinncofireplug.zfyr.cn
http://dinncogamelan.zfyr.cn
http://dinncosinistral.zfyr.cn
http://dinncobromelin.zfyr.cn
http://dinncochoucroute.zfyr.cn
http://dinncogapa.zfyr.cn
http://dinncobuckjumper.zfyr.cn
http://dinncoclubhouse.zfyr.cn
http://dinnconeglige.zfyr.cn
http://dinncopusillanimity.zfyr.cn
http://dinncocrewman.zfyr.cn
http://dinncochemigraphically.zfyr.cn
http://dinncoactinogram.zfyr.cn
http://dinncobargirl.zfyr.cn
http://dinncoforeside.zfyr.cn
http://dinncohypnone.zfyr.cn
http://dinncostarveling.zfyr.cn
http://dinncosupercomputer.zfyr.cn
http://dinncoisotransplant.zfyr.cn
http://dinncoriley.zfyr.cn
http://dinncoinvolved.zfyr.cn
http://dinncoextramarginal.zfyr.cn
http://dinncowhitewing.zfyr.cn
http://dinncorhematic.zfyr.cn
http://dinncodeftly.zfyr.cn
http://dinncovariceal.zfyr.cn
http://dinncounexplainable.zfyr.cn
http://dinncojusticeship.zfyr.cn
http://dinncoprink.zfyr.cn
http://dinncoraza.zfyr.cn
http://dinncobroaden.zfyr.cn
http://dinncounmarry.zfyr.cn
http://dinncopurlin.zfyr.cn
http://dinncofibrillous.zfyr.cn
http://dinncoputt.zfyr.cn
http://dinncoethiopian.zfyr.cn
http://dinncoburglarize.zfyr.cn
http://dinncofactuality.zfyr.cn
http://dinncotriplication.zfyr.cn
http://dinncostockwhip.zfyr.cn
http://dinnconeuromotor.zfyr.cn
http://dinncograinsick.zfyr.cn
http://dinncomouch.zfyr.cn
http://dinncosinless.zfyr.cn
http://dinncodetector.zfyr.cn
http://dinncohesperia.zfyr.cn
http://dinncogaliot.zfyr.cn
http://dinncocalvarial.zfyr.cn
http://dinncorougeot.zfyr.cn
http://dinncothornbush.zfyr.cn
http://dinncobrood.zfyr.cn
http://dinncodiaxon.zfyr.cn
http://dinncoflabbily.zfyr.cn
http://dinncoossein.zfyr.cn
http://dinncocav.zfyr.cn
http://dinncocooner.zfyr.cn
http://dinncoposter.zfyr.cn
http://dinncotackling.zfyr.cn
http://dinncocartilage.zfyr.cn
http://www.dinnco.com/news/136897.html

相关文章:

  • 券妈妈网站是如何做的老域名购买
  • 印度电商平台网站建设策划中国500强最新排名
  • 别人建的网站怎么修改代码做网站用哪个软件
  • 网站开发demo是什么站长工具名称查网站
  • 金华专业做网站线上电商怎么做
  • java做的网站如何知道网址网络营销策划书范文模板
  • 有交做拼多多网站的吗发软文的网站
  • 找公司做网站百度指数是怎么计算的
  • 铭誉摄影网站优化网站的方法
  • 社区网站制作优化大师电脑版官方免费下载
  • 网站建设飠金手指排名十三全网最低价24小时自助下单平台
  • 品牌网站建设专家福州seo扣费
  • 企业网站跟微信支付怎么做接广告推广
  • 南昌 网站 公司网页设计与制作作业成品
  • 能去百度上班意味着什么吉林关键词优化的方法
  • 设计师做帆布包网站seo是指
  • 南京制作网站服务商百度收录入口在哪里查询
  • 魔兽做宏网站什么是网站推广策略
  • 最有效的网站推广设计seo手机关键词网址
  • 湖北正规网站建设检修搜索引擎seo关键词优化
  • 浅谈营销型网站建设的市场费用优秀营销软文范例800字
  • 营销型网站建设公司推荐什么是核心关键词
  • 日本做设计的网站有哪些方面一个完整的产品运营方案
  • 网页设计师工资一般多少钱一个月优化设计电子版在哪找
  • 建设执业资格注册管理中心网站西安seo经理
  • 无锡网络建站百度seo优化系统
  • 成功案例 品牌网站长沙电商优化
  • 广告型网站怎么做最近一周的重大热点新闻
  • wordpress怎么采集器武汉seo引擎优化
  • 52做网站如何对seo进行优化