Skip to content

Latest commit

 

History

History
67 lines (49 loc) · 1.87 KB

_2374. Node With Highest Edge Score.md

File metadata and controls

67 lines (49 loc) · 1.87 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 18, 2024

Last updated : June 18, 2024


Related Topics : Hash Table, Graph

Acceptance Rate : 48.11 %


Solutions

Python

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