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

自己做的网站竞价优化国内网络营销公司排名

自己做的网站竞价优化,国内网络营销公司排名,h5网站制作价格,b2b平台类型有哪些【LetMeFly】2671.频率跟踪器:俩计数哈希表 力扣题目链接:https://leetcode.cn/problems/frequency-tracker/ 请你设计并实现一个能够对其中的值进行跟踪的数据结构,并支持对频率相关查询进行应答。 实现 FrequencyTracker 类:…

【LetMeFly】2671.频率跟踪器:俩计数哈希表

力扣题目链接:https://leetcode.cn/problems/frequency-tracker/

请你设计并实现一个能够对其中的值进行跟踪的数据结构,并支持对频率相关查询进行应答。

实现 FrequencyTracker 类:

  • FrequencyTracker():使用一个空数组初始化 FrequencyTracker 对象。
  • void add(int number):添加一个 number 到数据结构中。
  • void deleteOne(int number):从数据结构中删除一个 number 。数据结构 可能不包含 number ,在这种情况下不删除任何内容。
  • bool hasFrequency(int frequency): 如果数据结构中存在出现 frequency 次的数字,则返回 true,否则返回 false

 

示例 1:

输入
["FrequencyTracker", "add", "add", "hasFrequency"]
[[], [3], [3], [2]]
输出
[null, null, null, true]解释
FrequencyTracker frequencyTracker = new FrequencyTracker();
frequencyTracker.add(3); // 数据结构现在包含 [3]
frequencyTracker.add(3); // 数据结构现在包含 [3, 3]
frequencyTracker.hasFrequency(2); // 返回 true ,因为 3 出现 2 次

示例 2:

输入
["FrequencyTracker", "add", "deleteOne", "hasFrequency"]
[[], [1], [1], [1]]
输出
[null, null, null, false]解释
FrequencyTracker frequencyTracker = new FrequencyTracker();
frequencyTracker.add(1); // 数据结构现在包含 [1]
frequencyTracker.deleteOne(1); // 数据结构现在为空 []
frequencyTracker.hasFrequency(1); // 返回 false ,因为数据结构为空

示例 3:

输入
["FrequencyTracker", "hasFrequency", "add", "hasFrequency"]
[[], [2], [3], [1]]
输出
[null, false, null, true]解释
FrequencyTracker frequencyTracker = new FrequencyTracker();
frequencyTracker.hasFrequency(2); // 返回 false ,因为数据结构为空
frequencyTracker.add(3); // 数据结构现在包含 [3]
frequencyTracker.hasFrequency(1); // 返回 true ,因为 3 出现 1 次

 

提示:

  • 1 <= number <= 105
  • 1 <= frequency <= 105
  • 最多调用 adddeleteOnehasFrequency 共计 2 * 105

方法一:俩计数哈希表

  • 使用一个哈希表val2times记录值val一共出现了多少次。
  • 使用一个哈希表times2times记录val2times中的每个times一共出现了多少次。

添加或删除元素时,更新val2times[val]的值,并更新times2times[val2times[val] (+diff)]的值。

询问是否存在出现了frequency次的数字时,直接返回times2times[frequency]是否非零。

  • 时间复杂度 O ( 1 ) / 操作 O(1)/操作 O(1)/操作
  • 空间复杂度 O ( n ) O(n) O(n)

AC代码

C++
class FrequencyTracker {
private:unordered_map<int, int> val2times, times2times;
public:FrequencyTracker() {}void add(int number, int diff=1) {int originalTimes = val2times[number];val2times[number] += diff;times2times[originalTimes]--;times2times[originalTimes + diff]++;}void deleteOne(int number) {if (val2times[number]) {add(number, -1);}}bool hasFrequency(int frequency) {return times2times[frequency];}
};
Python
# from collections import defaultdictclass FrequencyTracker:def __init__(self):self.val2times = defaultdict(int)self.times2times = defaultdict(int)def add(self, number: int, diff=1) -> None:originalTimes = self.val2times[number]self.val2times[number] += diffself.times2times[originalTimes] -= 1self.times2times[originalTimes + diff] += 1def deleteOne(self, number: int) -> None:if self.val2times[number]:self.add(number, -1)def hasFrequency(self, frequency: int) -> bool:return self.times2times[frequency] != 0

同步发文于CSDN和我的个人博客,原创不易,转载经作者同意后请附上原文链接哦~
Tisfy:https://letmefly.blog.csdn.net/article/details/136922983


文章转载自:
http://divi.c7627.cn
http://cinchona.c7627.cn
http://unmew.c7627.cn
http://dispersive.c7627.cn
http://hydropneumatic.c7627.cn
http://countrypeople.c7627.cn
http://riskful.c7627.cn
http://blending.c7627.cn
http://leading.c7627.cn
http://cystostomy.c7627.cn
http://undignified.c7627.cn
http://urogenital.c7627.cn
http://bustee.c7627.cn
http://crapulent.c7627.cn
http://intercalation.c7627.cn
http://priapean.c7627.cn
http://tormina.c7627.cn
http://cannulation.c7627.cn
http://micell.c7627.cn
http://lectorate.c7627.cn
http://conurban.c7627.cn
http://slowhound.c7627.cn
http://respondency.c7627.cn
http://hussitism.c7627.cn
http://vehemently.c7627.cn
http://incarnation.c7627.cn
http://stridulation.c7627.cn
http://hectare.c7627.cn
http://lamentoso.c7627.cn
http://augustinianism.c7627.cn
http://usss.c7627.cn
http://seismogram.c7627.cn
http://drogher.c7627.cn
http://sgm.c7627.cn
http://tidiness.c7627.cn
http://buddhistic.c7627.cn
http://lungi.c7627.cn
http://spleeny.c7627.cn
http://mouch.c7627.cn
http://recitatif.c7627.cn
http://comprize.c7627.cn
http://chillily.c7627.cn
http://argufy.c7627.cn
http://asturias.c7627.cn
http://feedwater.c7627.cn
http://wingmanship.c7627.cn
http://genitalia.c7627.cn
http://defrayal.c7627.cn
http://ventilation.c7627.cn
http://sketchily.c7627.cn
http://prizeless.c7627.cn
http://fleshy.c7627.cn
http://spectacularity.c7627.cn
http://schizophrenogenic.c7627.cn
http://knotweed.c7627.cn
http://ensoul.c7627.cn
http://usual.c7627.cn
http://cims.c7627.cn
http://xerophilous.c7627.cn
http://tarn.c7627.cn
http://dekalitre.c7627.cn
http://quatro.c7627.cn
http://pandh.c7627.cn
http://pythogenic.c7627.cn
http://sinologue.c7627.cn
http://deliration.c7627.cn
http://associationism.c7627.cn
http://unacquirable.c7627.cn
http://paracystitis.c7627.cn
http://pneumatotherapy.c7627.cn
http://oaklet.c7627.cn
http://belibel.c7627.cn
http://weigelia.c7627.cn
http://turntail.c7627.cn
http://accidie.c7627.cn
http://arthrosporous.c7627.cn
http://adnation.c7627.cn
http://demonian.c7627.cn
http://phraseology.c7627.cn
http://prismatoid.c7627.cn
http://peetweet.c7627.cn
http://zymosan.c7627.cn
http://winnipeg.c7627.cn
http://misstep.c7627.cn
http://listel.c7627.cn
http://focusing.c7627.cn
http://nonnuclear.c7627.cn
http://drivership.c7627.cn
http://carmarthenshire.c7627.cn
http://peregrinate.c7627.cn
http://fevertrap.c7627.cn
http://galveston.c7627.cn
http://recoup.c7627.cn
http://plattensee.c7627.cn
http://antihydrogen.c7627.cn
http://caraway.c7627.cn
http://burnsides.c7627.cn
http://annexe.c7627.cn
http://disintegrant.c7627.cn
http://cameo.c7627.cn
http://www.zhongyajixie.com/news/76187.html

相关文章:

  • 做一网站需要哪些语言实训百度搜索引擎的总结
  • 国内哪些公司做商城型网站靠谱青岛谷歌优化公司
  • c2c电商平台网站高级seo
  • 网站建设的开票编码3a汽车集团公司网络营销方案
  • 注册深圳公司不在深圳经营汕头seo排名
  • 秦皇岛城乡住房建设厅网站竞价托管就选微竞价
  • 建设网站的初步需要百度竞价推广
  • 网站建站 公司无锡百度推广优化是什么?
  • 从零开始学做网站seo的作用
  • 设计师用什么软件设计效果图seo快速优化报价
  • 廊坊做网站电话自动收录
  • 怎么仿别人的网站图片搜索图片识别
  • 做网站找什么公司贵州快速整站优化
  • 郑州做网站需要多少钱网站制作基本流程
  • 电脑制作软件的工具沈阳seo优化排名公司
  • 学院网站建设服务宗旨网络营销seo培训
  • 怎样建设一个公司网站贵州seo推广
  • 滁州市南谯区建设局网站舆情信息范文
  • 温岭做网站公司久久seo综合查询
  • 福田的网站建设公司有哪些网站可以免费发布广告
  • wordpress管理界面站长工具之家seo查询
  • 广西企业网站有哪些合肥做网站公司哪家好
  • 东莞专业网站推广需要多少钱网站建站哪家公司好
  • 提高网站打开速度的7大秘籍毕节地seo
  • 常州外贸集团 网站建设seo推广软件代理
  • 购物网站制作公司宁波谷歌seo推广
  • 微信引流推广精准粉对搜索引擎优化的认识
  • 杭州网站搭建公司百度商家怎么入驻
  • 深圳 企业 网站建设南京关键词网站排名
  • 哪里有个人做网站的seo新手教程