Skip to content

Instantly share code, notes, and snippets.

@muddlebee
Created December 19, 2019 17:09
Show Gist options
  • Save muddlebee/edab820131bb43aecfa1958a2298749a to your computer and use it in GitHub Desktop.
Save muddlebee/edab820131bb43aecfa1958a2298749a to your computer and use it in GitHub Desktop.
def secondMax(nums):
"""
:type num: List[string]
"""
if len(nums) == 0:
return -1
fmax = float('-inf')
for i in range(0,len(nums)):
if fmax < float(nums[i]):
fmax = float(nums[i])
smax = float('-inf')
for i in range(0,len(nums)):
if float(nums[i]) < fmax and smax < float(nums[i]):
smax = float(nums[i])
if smax == float('-inf'):
return -1
return smax
#Example usage
print(secondMax(['1.1','1','2.2','3.2','4.2']*3000))
assert secondMax(['1.1','1.2','2.2','3.2','4.2']*3000)==3.2
assert secondMax(["1","2","3"])==2
assert secondMax(["3", "-2"])==-2
assert secondMax(["4", "4", "4"])==-1
assert secondMax([])==-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment