Skip to content
LC-0747 Easy LeetCode

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
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