2 Python


  • 0
    def dominantIndex(self, nums):
        a, b = sorted(nums + [0])[-2:]
        return nums.index(b) if b >= 2 * a else -1
    
    def dominantIndex(self, nums):
        x = max(nums)
        i = nums.index(x)
        nums[i] = 0
        return i if x >= 2 * max(nums) else -1

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.