Skip to content

Commit

Permalink
我的解法
Browse files Browse the repository at this point in the history
  • Loading branch information
rinwf committed Sep 18, 2018
1 parent 21d4302 commit 6d478cb
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lc747. Largest Number At Least Twice of Others.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution:
def dominantIndex(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
maxnum = nums[0]
secmax = 0
result = True
idx = 0
for i in range(1, len(nums)):
if nums[i] > maxnum:
idx = i
secmax = maxnum
maxnum = nums[i]
result = (maxnum >= 2 * secmax)
else:
if maxnum < 2 * nums[i]:
result = False
return idx if result else -1


nums = [1, 2, 3, 4]
s = Solution()
print(s.dominantIndex(nums))

0 comments on commit 6d478cb

Please sign in to comment.