호출제한
2026년 2월 10일 16:04분
package com.jesusbornd.exodus;
public class Exodus_30_Chapter_Lv3 {
static class RateLimiter {
private long last = 0;
private final long cooldownMs;
RateLimiter(long cooldownMs) {
this.cooldownMs = cooldownMs;
}
boolean allow(long nowMs) {
if (nowMs - last < cooldownMs) return false;
last = nowMs;
return true;
}
}
public static void main(String[] args) {
RateLimiter incense = new RateLimiter(1000);
long t1 = 1000;
long t2 = 1500;
long t3 = 2500;
System.out.println(incense.allow(t1));
System.out.println(incense.allow(t2));
System.out.println(incense.allow(t3));
}
}
class RateLimiter:
def __init__(self, cooldown_ms: int):
self.last = 0
self.cooldown_ms = cooldown_ms
def allow(self, now_ms: int) -> bool:
if now_ms - self.last < self.cooldown_ms:
return False
self.last = now_ms
return True
incense = RateLimiter(1000)
t1 = 1000
t2 = 1500
t3 = 2500
print(incense.allow(t1))
print(incense.allow(t2))
print(incense.allow(t3))
Search
Categories
← 목록으로
Comments
아직 댓글이 없습니다!