Created
September 20, 2021 18:27
-
-
Save kiramishima/ca13165f3511791c39c12664981a373b to your computer and use it in GitHub Desktop.
Mi solucion del 2
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 MaxProfit(priceAsString): | |
list = [int(i) for i in priceAsString.split(',')] | |
print(list) | |
minVal = min(list) | |
indexMinVal = list.index(minVal) | |
if indexMinVal < len(list): | |
list2 = list[indexMinVal::] | |
if len(list2) == 1: | |
return 0 | |
elif len(list2) <= 2: | |
list.pop(indexMinVal) | |
d = ','.join(str(e) for e in list) | |
return MaxProfit(d) | |
else: | |
maxVal = max(list[indexMinVal::]) | |
indexMaxVal = list.index(maxVal) | |
return maxVal - minVal | |
else: | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment