Web Logger

本文介绍如何实现一个Web日志记录器,它包含两个方法:记录指定时间戳的点击,并获取过去5分钟内的点击次数。方法调用按时间戳升序进行,可以使用Deque数据结构有效地处理这些操作。
摘要由CSDN通过智能技术生成

Implement a web logger, which provide two methods:

  1. hit(timestamp), record a hit at given timestamp.
  2. get_hit_count_in_last_5_minutes(timestamp), get hit count in last 5 minutes.

the two methods will be called with non-descending timestamp (in sec).

Example

Example 1:

Input:
  hit(1);
  hit(2);
  get_hit_count_in_last_5_minutes(3);
  hit(300);
  get_hit_count_in_last_5_minutes(300);
  get_hit_count_in_last_5_minutes(301);
Output:
  2
  3
  2

Example 2:

Input:
  hit(1)
  hit(1)
  hit(1)
  hit(2)
  get_hit_count_in_last_5_minutes(3)
  hit(300)
  get_hit_count_in_last_5_minutes(300)
  get_hit_count_in_last_5_minutes(301)
  get_hit_count_in_last_5_minutes(302)
  get_hit_count_in_last_5_minutes(900)
  get_hit_count_in_last_5_minutes(900)
Output:
  4
  5
  2
  1
  0
  0

Notice

Th

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值