码迷,mamicode.com
首页 > 其他好文 > 详细

359. Logger Rate Limiter

时间:2016-07-15 09:26:32      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

   /*
     * 359. Logger Rate Limiter
     * 2016-7-14 by Mingyang
     * 很简单的HashMap,不详谈
     */
    class Logger {
        HashMap<String, Integer> map;
        /** Initialize your data structure here. */
        public Logger() {
            map = new HashMap<String, Integer>();
        }
        /**
         * Returns true if the message should be printed in the given timestamp,
         * otherwise returns false. If this method returns false, the message
         * will not be printed. The timestamp is in seconds granularity.
         */
        public boolean shouldPrintMessage(int timestamp, String message) {
            if (!map.containsKey(message)) {
                map.put(message, timestamp);
                return true;
            } else {
                int temp = map.get(message);
                if (timestamp - temp < 10) {
                    return false;
                } else {
                    map.put(message, timestamp);
                    return true;
                }
            }
        }
    }

 

359. Logger Rate Limiter

标签:

原文地址:http://www.cnblogs.com/zmyvszk/p/5672342.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!