Skip to content

Instantly share code, notes, and snippets.

@muddlebee
Last active December 19, 2019 13:58
Show Gist options
  • Save muddlebee/1c66d22dd31ffa031b1a850eabc230b5 to your computer and use it in GitHub Desktop.
Save muddlebee/1c66d22dd31ffa031b1a850eabc230b5 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 < int(nums[i]):
fmax = int(nums[i])
smax = float('-inf')
for i in range(0,len(nums)):
if int(nums[i]) < fmax and smax < int(nums[i]):
smax = int(nums[i])
if smax == float('-inf'):
return -1
return smax
#Example usage
print(secondMax(['1','1','2','3','4']*3000))
#Assertions
def assertc(actual, expect):
assert actual, expect
assert secondMax(['1','1','2','3','4']*3000),3
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