All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 18, 2024
Last updated : June 18, 2024
Related Topics : Hash Table, Graph
Acceptance Rate : 48.11 %
class Solution:
def edgeScore(self, edges: List[int]) -> int:
nodeSums = defaultdict(int)
for i, targetEdge in enumerate(edges) :
nodeSums[targetEdge] += i
return max(nodeSums.keys(), key=lambda x : (nodeSums[x], -x))
class Solution:
def edgeScore(self, edges: List[int]) -> int:
nodeSums = [0] * len(edges)
for i, targetEdge in enumerate(edges) :
nodeSums[targetEdge] += i
return max([i for i in range(len(edges))], key=lambda x: (nodeSums[x], -x))
class Solution:
def edgeScore(self, edges: List[int]) -> int:
nodeSums = [0] * len(edges)
maxx = 0
indx = 0
for i, targetEdge in enumerate(edges) :
nodeSums[targetEdge] += i
if maxx < nodeSums[targetEdge] or (maxx == nodeSums[targetEdge] and indx > targetEdge):
maxx = nodeSums[targetEdge]
indx = targetEdge
return indx