当前位置: 首页 > 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.yayakq.cn/news/614523/

相关文章:

  • 中国保险行业协会网站腾讯云网站搭建教程
  • 电商网站开发建设建公司网站的详细步骤
  • 驻马店营销型网站建设优化推广内账免费的财务软件
  • 网站模板中文乱码营销型网站建设主要教学内容
  • 国企网站建设标准wordpress有赞云
  • wordpress做商品筛选整站优化cms
  • 手机网站建设经验建立一个自己的网页
  • 专业响应式网站制作网站失败后怎么重新建设
  • 网站服务器要求上海网站推广模板
  • 找网站开发公司网站访客记录 是后台做吗
  • 安全网站建设报价清单北京制作网站主页
  • 制作企业网站的步骤win7系统可以做网站吗
  • 门户网站建设进一步提升个人网站建设联系
  • 甘肃省省经合局网站建设的通知做冠县梨园网站怎么做
  • 石家庄科技网站什么是oa系统软件
  • 网站建设公司多少钱网站建设维护兼职
  • 国外哪些网站有黄图公司网站主机流量30g每月够用吗
  • 全屏响应式网站模板wordpress常规地址改错了怎么办
  • 天津网站建设企业系统广告网络平台
  • 高端网站建设设计网页设计图片加载不出来
  • 网站制作公司 恶意宁波seo网站
  • 岳阳网站开发服务做网站的电话号码
  • 广州十大高端网站建设公司新品发布会主题名字
  • 通辽网站公司网站设计空间
  • 用wordpress做企业网站wordpress $limit
  • 购物网站两化融合建设项目报告成立公司注册资金
  • 山西城乡与住房建设厅网站成品网站w灬源码16伊园
  • 网站建设与管理期末北京页面设计制作
  • 一个网站一个月发多少外链比较合适做面包有关电影网站
  • asp做网站 的pdf教程网站优化工具升上去