747-Largest-Number-At-Least-Twice-Of-Others

Sat 17 May 2025

https://leetcode.com/problems/largest-number-at-least-twice-of-others

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def dominantIndex(self, nums: List[int]) -> int:
    max = 0
    secondMax = 0

    for i, num in enumerate(nums):
      if num > max:
        secondMax = max
        max = num
        ans = i
      elif num > secondMax:
        secondMax = num

    return ans if max >= 2 * secondMax else -1
new Solution().dominantIndex()

Score: 5

Category: leetcode