Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save luojiyin1987/910737b1a67fff4ebfb9eadca37fe406 to your computer and use it in GitHub Desktop.
Save luojiyin1987/910737b1a67fff4ebfb9eadca37fe406 to your computer and use it in GitHub Desktop.
Largest Number At Least Twice of Others
class Solution(object):
def dominantIndex(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
maxn = max(nums)
for num in nums:
if num != maxn and 2 * num > maxn:
return -1
return nums.index(maxn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment