Advertisement
HXXXXJ

rate limiter

Mar 12th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.58 KB | None | 0 0
  1.     var map : [String: Int]
  2.     /** Initialize your data structure here. */
  3.     init() {
  4.         map = [String:Int]()
  5.     }
  6.    
  7.     /** Returns true if the message should be printed in the given timestamp, otherwise returns false.
  8.         If this method returns false, the message will not be printed.
  9.         The timestamp is in seconds granularity. */
  10.     func shouldPrintMessage(_ timestamp: Int, _ message: String) -> Bool {
  11.         if let time = map[message] , timestamp - time < 10 {
  12.             return false
  13.         }
  14.         map[message] = timestamp
  15.         return true
  16.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement