当前位置:网站首页>LeetCode 362. Design Hit Counter
LeetCode 362. Design Hit Counter
2022-08-10 11:57:00 【Mizuna pen】
The question is locked,Visit the solution address:https://blog.csdn.net/jmspan/article/details/51738164
hit(timestamp)Pass in a moment,Indicates that a tap was made at that moment;
gethit(timestamp) Pass in a moment,means at that moment5分钟内的敲击次数
使用一个map,Save the time and number of taps.When returning the number of hits,遍历整个map;如果超时了,就删除.只保留5分钟之内的.
int count = 0;
Map<Integer, Integer> map = new HashMap<>();
public void hit(int timestamp) {
count++;
int result = map.getOrDefault(timestamp,0) + 1;
map.put(timestamp, result);
// getHits(timestamp);
}
public int getHits(int timestamp) {
Iterator<Map.Entry<Integer, Integer>> iterator = map.entrySet().iterator();
Map.Entry<Integer, Integer> entry;
while (iterator.hasNext()) {
entry = iterator.next();
if (timestamp-entry.getKey() >= 300) {
iterator.remove();
count-=entry.getValue();
}
}
return count;
}
边栏推荐
- 力扣练习——56 寻找右区间
- leetcode 823. Binary Trees With Factors(因子二叉树)
- Introduction to Software Architecture
- Network sockets (UDP and TCP programming)
- LeetCode_628_三个数的最大乘积
- A case of violent parameter tuning in machine learning
- 【Redis】内存回收策略
- 皕杰报表在传参乱码
- What are some useful performance testing tools recommended? Performance testing report charging standards
- Network Fundamentals (Section 1)
猜你喜欢
随机推荐
中芯CIM国产化项目暂停?上扬软件:未停摆,改为远程开发!
LeetCode50天刷题计划(Day 17—— 下一个序列(14.50-16.30)
项目部署、
传三星3nm斩获第二家客户,目前产能已供不应求
LeetCode 109. 有序链表转换二叉搜索树
LeetCode_443_压缩字符串
Article take you understand interrupt the key driver of polling mechanism
使用.NET简单实现一个Redis的高性能克隆版(六)
使用哈工大LTP测试分词并且增加自定义字典
VSCode远程连接服务器报错:Could not establish connection to “xxxxxx”的可能错误原因及解决
微信小程序提交审核历史版本记录从哪里查看
CPU多级缓存与缓存一致性
为什么Redis很快
【Untitled】
Does your child lack self-discipline?Ape Counseling: Pay attention to "blank" in the schedule to give children more control
LCD驱动端与设备端名称匹配过程分析(Tiny4412)
【mysql】explain介绍[通俗易懂]
Licking Exercise - 60 Maximum key-value sum of binary search subtrees
基于UiAutomator2+PageObject模式开展APP自动化测试实战
做自媒体月入几万?博主们都在用的几个自媒体工具









