Skip to content

Instantly share code, notes, and snippets.

@muddlebee
Created December 19, 2019 17:30
Show Gist options
  • Save muddlebee/1fd1fbe248c33e569b854ce1698bcee3 to your computer and use it in GitHub Desktop.
Save muddlebee/1fd1fbe248c33e569b854ce1698bcee3 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')
flag = True
for i in range(0,len(nums)):
if float(nums[i]) < fmax and smax <= float(nums[i]):
smax = float(nums[i])
flag = False
if flag:
return -1
return smax
#Example usage
print(secondMax([1, float('-inf'),float('-inf')]))
assert secondMax([1, float('-inf'),float('-inf')])==float('-inf')
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment