You are viewing a single comment's thread. Return to all comments →
Similar but no need of classes:
def median(v, d): count = 0 if d%2==0: m1 = None m2 = None for i in range(len(v)): count += v[i] if count >= d/2 and m1 is None: m1 = i if count >= d/2 + 1: m2 = i break return (m1 + m2)/2 else: for i in range(len(v)): count += v[i] if count > d/2: return i return -1 def activityNotifications(expenditure, d): dq = deque(expenditure[: d]) v = [0]*201 for n in dq: v[n] += 1 count = 0 for current in expenditure[d:]: if current >= median(v, d)*2: count += 1 v[current] += 1 dq.append(current) v[dq.popleft()] -= 1 return count
Seems like cookies are disabled on this browser, please enable them to open this website
Fraudulent Activity Notifications
You are viewing a single comment's thread. Return to all comments →
Similar but no need of classes: