LeetCode747-至少是其他数字两倍的最大数

原题链接:https://leetcode-cn.com/problems/largest-number-at-least-twice-of-others/

 

代码

 1 class Solution:
 2     def dominantIndex(self, nums: List[int]) -> int:
 3         if not nums:
 4             return -1
 5         if len(set(nums)) == 1:
 6             return 0
 7         max_num = max(nums)
 8         index = nums.index(max_num)
 9         for i in range(len(nums)):
10             if nums[i] == max_num:
11                 continue
12             else:
13                 if nums[i] * 2 > max_num:
14                     index = -1
15                     break
16         return index

 

posted @ 2022-01-13 23:54  CaptainDragonfly  阅读(19)  评论(0编辑  收藏  举报