-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1086-high-five.py
More file actions
30 lines (28 loc) · 954 Bytes
/
1086-high-five.py
File metadata and controls
30 lines (28 loc) · 954 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
# LINT 613
# This solution is from lintcode 613
# Originally, in leet 1086
# There is no Record class
# You can directly `for id, val in results` is OK to go
'''
Definition for a Record
class Record:
def __init__(self, id, score):
self.id = id
self.score = score
'''
from heapq import heappush, heappop
class Solution:
def highFive(self, results):
students = {}
for record in results:
if record.id not in students:
students[record.id] = [record.score]
continue
if len(students[record.id]) < 5:
heappush(students[record.id], record.score)
elif students[record.id][0] < record.score:
heappush(students[record.id], record.score)
heappop(students[record.id])
for key, scores in students.items():
students[key] = sum(scores) / 5
return students