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. 推文计数相关推荐

  1. LeetCode 1348. 推文计数(哈希map+set)

    1. 题目 请你实现一个能够支持以下两种方法的推文计数类 TweetCounts: recordTweet(string tweetName, int time) 记录推文发布情况:用户 tweetN ...

  2. 1348. 推文计数

    请你实现一个能够支持以下两种方法的推文计数类 TweetCounts: 1. recordTweet(string tweetName, int time) 记录推文发布情况:用户 tweetName ...

  3. Leetcode 1348:推文计数

    题目描述 请你实现一个能够支持以下两种方法的推文计数类 TweetCounts: 1. recordTweet(string tweetName, int time) 记录推文发布情况:用户 twee ...

  4. 大数据谈论热点有_数据科学推文分析–人们在谈论什么工具?

    大数据谈论热点有 By Chris Musselle PhD, Mango UK 克里斯·穆塞尔(Chris Musselle)博士,英国芒果 At ­Mango we use a variety o ...

  5. 情感分析朴素贝叶斯_朴素贝叶斯推文的情感分析

    情感分析朴素贝叶斯 Millions of tweets are posted every second. It helps us know how the public is responding ...

  6. lstm 文本分类_带有lstm和单词嵌入的灾难推文上的文本分类

    lstm 文本分类 This was my first Kaggle notebook and I thought why not write it on Medium too? Ť他是我第一次Kag ...

  7. 如何使用PHP机器学习分析推文情感

    This article was peer reviewed by Wern Ancheta. Thanks to all of SitePoint's peer reviewers for maki ...

  8. 推特开发者账号申请失败【推特开发者文档系列7】——通过API接口发布、检索推文

    文章转自:https://www.jianshu.com/p/2c208994ff9a 本系列是对推特开发者文档进行的翻译,以便帮助开发人员使用API接口,难免有些地方存在不足,还请谅解. 关于如何获 ...

  9. 微信推文属性的关联分析 by Apriori算法

    本文通过Apriori算法来对某公司的微信推文属性的关联分析. 本文的目的 找出可让 ['阅读量超过1K'] 的因素,以便达到这些因素使微信推文阅读量提升. 本文的结论 若想让微信推文阅读量超过1K, ...

最新文章

  1. NYOJ 353 3D dungeon 【bfs】
  2. Flutter 在铭师堂的实践
  3. python读取单元格的值csv,比较单元格值的csv文件python
  4. intelli idea新建无scala class选项解决方案
  5. 一个可以下载Github指定子文件夹的Chrome插件
  6. mysql 作业调度及问题解决
  7. 2014蓝桥杯:李白打酒;奇怪的分式(枚举,最大公约数)
  8. Snagit 2021 for mac(强大的屏幕截图工具)
  9. 随手记_科研攻略_常犯错误
  10. Word2vec 详解
  11. sqlmap的安装与使用
  12. 锁存器、触发器和寄存器
  13. 南航C语言答案,2009-2011南航复试题(回忆版) 予人玫瑰,手有余香
  14. 课堂派“互动课件”文件下载
  15. 华为云服务查找手机_华为云服务登录入口
  16. 求π的值C++--递归求阶乘、浮点数精度控制技巧
  17. [LOJ6515]贪玩蓝月
  18. Git 学习日记-01
  19. Python 实现远程监控中心
  20. Python-爬虫请求~requsts~get

热门文章

  1. C++ 两点之间最短距离
  2. 【天坑】BLAST比对序列时遭受的痛苦
  3. 《Python 深度学习》6.1.3 整合在一起:从原始文本到词嵌入
  4. 二、谈谈对数据库中索引的理解
  5. Paste for Mac(剪切板历史管理工具)
  6. python中turtle隐藏画笔_python中Turtle的画笔命令有哪些?
  7. Vue + D3 动态可视化图实现之一:折线图
  8. SpringMVC简介及第一个MVC程序
  9. 如何利用PuTTY连接Windows主机和Linux虚拟机
  10. JavaScript—箭头函数