Skip to content

Commit

Permalink
二分搜索
Browse files Browse the repository at this point in the history
  • Loading branch information
rinwf committed Nov 4, 2018
1 parent 561c1ae commit 251a1f1
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lc933. Number of Recent Calls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from bisect import bisect_left


class RecentCounter:

def __init__(self):
self.lst = []

def ping(self, t):
"""
:type t: int
:rtype: int
"""
self.lst.append(t)
lo = bisect_left(self.lst, (t - 3000))
return len(self.lst) - lo


# Your RecentCounter object will be instantiated and called as such:
obj = RecentCounter()
for t in [1, 100, 3001, 3002]:
param_1 = obj.ping(t)
print(param_1)

0 comments on commit 251a1f1

Please sign in to comment.