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

浦东网站建设广告投放平台排名

浦东网站建设,广告投放平台排名,大型门户网站设计,北京南站列车时刻表用链表存储用户发送的每一个推特&#xff0c;用堆获取最先的10条动态 class Twitter {Map<Integer,Set<Integer>> followMap;//规定最新的放到最后Map<Integer,Tweet> postMap;//优先队列(堆&#xff09;PriorityQueue<Tweet> priorityQueue;int time…

用链表存储用户发送的每一个推特,用堆获取最先的10条动态

class Twitter {Map<Integer,Set<Integer>> followMap;//规定最新的放到最后Map<Integer,Tweet> postMap;//优先队列(堆)PriorityQueue<Tweet> priorityQueue;int timeStamp = 0;int limit = 10;public Twitter() {followMap = new HashMap();postMap = new HashMap<>();//按照每一个推特发送的时间戳由大到小排布priorityQueue = new PriorityQueue<>((t1,t2) -> t2.timeStamp - t1.timeStamp);}//userId发送推特public void postTweet(int userId, int tweetId) {//首先根据postMap来获取userId对应发送到文章Tweet tweet = postMap.get(userId);//生成新的tweetTweet newTweet = new Tweet(tweetId, timeStamp++, tweet);postMap.put(userId,newTweet);}//根据userId获得自己和关注用户的10条推特,按时间顺序由近到远排序public List<Integer> getNewsFeed(int userId) {//因为每一个用户都有自己的优先队列,所以先清空优先队列priorityQueue.clear();//将自己和关注的用户发送的最新的推特id先放入到优先队列if (postMap.containsKey(userId))priorityQueue.offer(postMap.get(userId));Set<Integer> follows = followMap.get(userId);if (follows != null){for (Integer follow : follows) {if (postMap.containsKey(follow))priorityQueue.offer(postMap.get(follow));}}//现在用户和所有关注的推特都已经放入到优先队列,开始获取前10条int count = 0;ArrayList<Integer> result = new ArrayList<>();while (!priorityQueue.isEmpty() && count < limit){//获取头部,在优先队列中删除Tweet tweet = priorityQueue.poll();result.add(tweet.id);if (tweet.next != null)priorityQueue.offer(tweet.next);count++;}return result;}//关注public void follow(int followerId, int followeeId) {// 被关注人不能是自己if (followeeId == followerId) {return;}Set<Integer> follows = followMap.getOrDefault(followerId, new HashSet<>());follows.add(followeeId);followMap.put(followerId,follows);}//取关public void unfollow(int followerId, int followeeId) {// 被关注人不能是自己if (followeeId == followerId) {return;}Set<Integer> follows = followMap.getOrDefault(followerId, new HashSet<>());follows.remove(followeeId);followMap.put(followerId,follows);}
}
class Tweet{int id;int timeStamp;Tweet next;public Tweet(int id, int timeStamp) {this.id = id;this.timeStamp = timeStamp;}public Tweet(int id, int timeStamp, Tweet next) {this.id = id;this.timeStamp = timeStamp;this.next = next;}
}/*** Your Twitter object will be instantiated and called as such:* Twitter obj = new Twitter();* obj.postTweet(userId,tweetId);* List<Integer> param_2 = obj.getNewsFeed(userId);* obj.follow(followerId,followeeId);* obj.unfollow(followerId,followeeId);*/

http://www.shuangfujiaoyu.com/news/42812.html

相关文章:

  • 直播网站建设需要多少钱国外网站推广平台有哪些
  • 微信网站制作公司哪家好百度竞价推广常用到的工具
  • 网站制作模板代码网络营销推广方案有哪些
  • 怎么在网站后面制作官网俩个字优化落实疫情防控新十条
  • php class 做网站上海网站排名优化怎么做
  • 深圳网站设计公司费用是湖南网络推广服务
  • 网站的客服一般怎么做东莞网站seo公司
  • 在什么网站能帮人做ppt济南seo快速霸屏
  • 建网站入门公司业务推广
  • 如何做网站推广精优化工具箱
  • 营销网站的功能佛山seo代理计费
  • 做网站如何通过流量赚钱吗超级外链工具 增加外链中
  • 制作网站哪家强seo排名技术教程
  • 级a做爰片免费视网站看看下载百度app
  • 龙岩做网站开发哪家厉害合肥网站制作推广
  • 电脑网站有哪些电子商务主要干什么
  • 成都前几年网站建设公司考试培训
  • jsp怎么做网站的删除站长工具查询系统
  • 网站上传到虚拟主机seo排名优化推荐
  • 做一手房用什么网站好武汉网站推广很 棒
  • 销售案例网站成都百度seo优化公司
  • app downloadseo常用的优化工具
  • 企业管理培训课程目录徐州自动seo
  • 怎么上网站做简易注销的步骤网站快速收录付费入口
  • 网站规划建设与推广百度收录的网站多久更新一次
  • 日本网页设计网站2022年最火的新闻摘抄
  • 上海奉贤区政府seo从0到1怎么做
  • 网站建设公司潍坊网络营销推广的5种方法
  • 福州网站建设百度官方人工客服电话
  • 番禺做网站报价网络营销的10个特点