• 362. Design Hit Counter


    /*
     * 362. Design Hit Counter
     * 2016-7-15 by Mingyang
     * 这个题目意思很难懂,但其实本质上没什么东西
     */
    class HitCounter {
        public Queue<Integer> queue;
        /** Initialize your data structure here. */
        public HitCounter() {
            queue=new LinkedList();
        }    
        /** Record a hit.
            @param timestamp - The current timestamp (in seconds granularity). */
        public void hit(int timestamp) {
            queue.add(timestamp);
        }    
        /** Return the number of hits in the past 5 minutes.
            @param timestamp - The current timestamp (in seconds granularity). 301 和 1的差距刚好等于300,刚好出界 */
        public int getHits(int timestamp) {
            while(!queue.isEmpty()&&timestamp-queue.peek()>=300){
                queue.poll();
            }
            return queue.size();
        }
    }
  • 相关阅读:
    springBoot 与 springMVC的区别
    spring的IOC和AOP
    实现同步的三种方法
    台阶积水问题
    requsets模块和beautifulsoup模块
    爬虫
    rabbitMQ 消息队列
    Django框架
    mysql
    jQuery
  • 原文地址:https://www.cnblogs.com/zmyvszk/p/5675359.html
Copyright © 2020-2023  润新知