Last active
December 19, 2019 13:58
-
-
Save muddlebee/1c66d22dd31ffa031b1a850eabc230b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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