GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/src/Logger.java at master · feiteng/leetcode Expand file tree/ Copy pathLogger.javaMore file actions 37 lines (31 loc) · 841 Bytes / Copy pathLogger.javaFile metadata and controls37 lines (31 loc) · 841 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 import java.util.HashMap; import java.util.Map; public class Logger { Map<String, Integer> msgCount = new HashMap<>(); /** Initialize your data structure here. */ public Logger() { } /** * 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 ( !msgCount.containsKey( message ) || msgCount.get( message ) < timestamp - 10 ) { // update msg msgCount.put( message, timestamp ); return true; } return false; } } /** * Your Logger object will be instantiated and called as such: * Logger obj = new Logger(); * boolean param_1 = obj.shouldPrintMessage(timestamp,message); */ |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |