LeetCode 1348. 推文计数
https://leetcode-cn.com/problems/tweet-counts-per-frequency/
一开始使用vector<int>来存,这样每次插入都要排序,nlogn,太慢了,查询是log2n。
看题解用set<int>,插入比较快,查询log2n,遍历O(n)
class TweetCounts {
public:map<string,set<int>> record;TweetCounts() {}void recordTweet(string tweetName, int time) {if(record.count(tweetName)==0){record[tweetName]=set<int>();}record[tweetName].insert(time);}vector<int> getTweetCountsPerFrequency(string freq, string tweetName, int startTime, int endTime) {set<int> &arr=record[tweetName];int delta=60;if(freq=="hour")delta*=60;if(freq=="day"){delta*=(60*24);}vector<int> ans((endTime-startTime)/delta+1);auto begin=lower_bound(arr.begin(),arr.end(),startTime);auto end=upper_bound(arr.begin(),arr.end(),endTime);for(auto iter=begin;iter!=end;iter++){int time=*iter;ans[(time-startTime)/delta]++;}return ans;}
};/*** Your TweetCounts object will be instantiated and called as such:* TweetCounts* obj = new TweetCounts();* obj->recordTweet(tweetName,time);* vector<int> param_2 = obj->getTweetCountsPerFrequency(freq,tweetName,startTime,endTime);*/
LeetCode 1348. 推文计数相关推荐
- LeetCode 1348. 推文计数(哈希map+set)
1. 题目 请你实现一个能够支持以下两种方法的推文计数类 TweetCounts: recordTweet(string tweetName, int time) 记录推文发布情况:用户 tweetN ...
- 1348. 推文计数
请你实现一个能够支持以下两种方法的推文计数类 TweetCounts: 1. recordTweet(string tweetName, int time) 记录推文发布情况:用户 tweetName ...
- Leetcode 1348:推文计数
题目描述 请你实现一个能够支持以下两种方法的推文计数类 TweetCounts: 1. recordTweet(string tweetName, int time) 记录推文发布情况:用户 twee ...
- 大数据谈论热点有_数据科学推文分析–人们在谈论什么工具?
大数据谈论热点有 By Chris Musselle PhD, Mango UK 克里斯·穆塞尔(Chris Musselle)博士,英国芒果 At Mango we use a variety o ...
- 情感分析朴素贝叶斯_朴素贝叶斯推文的情感分析
情感分析朴素贝叶斯 Millions of tweets are posted every second. It helps us know how the public is responding ...
- lstm 文本分类_带有lstm和单词嵌入的灾难推文上的文本分类
lstm 文本分类 This was my first Kaggle notebook and I thought why not write it on Medium too? Ť他是我第一次Kag ...
- 如何使用PHP机器学习分析推文情感
This article was peer reviewed by Wern Ancheta. Thanks to all of SitePoint's peer reviewers for maki ...
- 推特开发者账号申请失败【推特开发者文档系列7】——通过API接口发布、检索推文
文章转自:https://www.jianshu.com/p/2c208994ff9a 本系列是对推特开发者文档进行的翻译,以便帮助开发人员使用API接口,难免有些地方存在不足,还请谅解. 关于如何获 ...
- 微信推文属性的关联分析 by Apriori算法
本文通过Apriori算法来对某公司的微信推文属性的关联分析. 本文的目的 找出可让 ['阅读量超过1K'] 的因素,以便达到这些因素使微信推文阅读量提升. 本文的结论 若想让微信推文阅读量超过1K, ...
最新文章
- NYOJ 353 3D dungeon 【bfs】
- Flutter 在铭师堂的实践
- python读取单元格的值csv,比较单元格值的csv文件python
- intelli idea新建无scala class选项解决方案
- 一个可以下载Github指定子文件夹的Chrome插件
- mysql 作业调度及问题解决
- 2014蓝桥杯:李白打酒;奇怪的分式(枚举,最大公约数)
- Snagit 2021 for mac(强大的屏幕截图工具)
- 随手记_科研攻略_常犯错误
- Word2vec 详解
- sqlmap的安装与使用
- 锁存器、触发器和寄存器
- 南航C语言答案,2009-2011南航复试题(回忆版) 予人玫瑰,手有余香
- 课堂派“互动课件”文件下载
- 华为云服务查找手机_华为云服务登录入口
- 求π的值C++--递归求阶乘、浮点数精度控制技巧
- [LOJ6515]贪玩蓝月
- Git 学习日记-01
- Python 实现远程监控中心
- Python-爬虫请求~requsts~get