Last active
September 15, 2021 11:43
-
-
Save shabarin/7a5d8e5bcf0088b5c56862463a57eefe 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 solutionC(a): | |
g = {} | |
maxnum = 1 | |
for i in range(0, len(a)): | |
if a[i] > 0: | |
g[a[i]] = 1 | |
maxnum = max(maxnum, a[i]) | |
for j in range(1, maxnum+2): | |
if j not in g: | |
return j | |
return 1 | |
def solutionD(a): | |
positive = filter(lambda x: x >= 0, a) | |
positive.sort() | |
if len(positive) == 0: | |
return 1 | |
prev = positive[0] | |
for i in range(1, len(positive)): | |
if (prev+1) < positive[i]: | |
return prev+1 | |
else: | |
prev = positive[i] | |
return prev+1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment