2374. Node With Highest Edge Score
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 48% Topics: Hash Table, Graph
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(n)
# freq table
class Solution(object):
def edgeScore(self, edges):
"""
:type edges: List[int]
:rtype: int
"""
score = [0]*len(edges)
for u, v in enumerate(edges):
score[v] += u
return max(xrange(len(edges)), key=lambda x:score[x])
Solution from kamyu104/LeetCode-Solutions · MIT