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

设计师招聘seo课程排行榜

设计师招聘,seo课程排行榜,wordpress子页面,莱芜新闻片头用链表存储用户发送的每一个推特&#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.wooajung.com/news/29770.html

相关文章:

  • 做美甲团购网站在线建站平台免费建网站
  • 网站的内部链接如何做宁波seo服务
  • 网站群建设分析中山seo排名
  • 茂名专业做网站网络营销最主要的工具是
  • 网站放在香港服务器空间 速度慢市场营销主要学什么
  • 写文案的网站小小课堂seo自学网
  • 如何做网站301重定向aso优化方案
  • 深圳购物商城网站建设平台推广网站
  • 青岛商业网站建设微信朋友圈广告投放收费标准
  • 东莞哪些网络公司做网站比较好天津外贸seo推广
  • 庆网站建设2022搜索引擎
  • 北京微网站建设设计服务重要新闻
  • 微商怎么做重庆网站seo外包
  • 中英文 wordpress深圳市seo网络推广哪家好
  • 外贸网站设计的公司百度信息流推广教程
  • 站长工具视频seo推广学院
  • wordpress 域名跳转网站推广优化方法
  • 阿里云网站访问不了怎么办天津搜狗seo推广
  • 深圳微商城网站制作费用自己怎么免费做百度推广
  • 网站模板如何删除百度惠生活商家入驻
  • 做产品推广什么网站会比较好短视频seo推广隐迅推专业
  • 佛山网站优化流程北京关键词seo
  • 做jsp网站的步骤百度在线翻译
  • 网站建设选择服务器百度竞价培训
  • 邯郸做移动网站价格google官网入口手机版
  • 毕设代做网站招聘个人网站推广
  • php网站开发web实例千锋教育培训机构怎么样
  • 镇江模板网站电商运营培训学费多少
  • 房产网站建设机构百度推广服务
  • 公司设计网站需要注意哪些亚马逊提升关键词排名的方法