747. Largest Number At Least Twice of Others
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 51% Topics: Array, Sorting
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
def dominantIndex(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
m = max(nums)
if all(m >= 2*x for x in nums if x != m):
return nums.index(m)
return -1
Solution from kamyu104/LeetCode-Solutions · MIT