Created
April 21, 2016 02:19
-
-
Save prmichaelsen/ff9e03a1c7806d5d3bfbb1f07965fa0f 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 maxProfit ( self, prices ): | |
previous_delta = 0 | |
delta = 0 | |
max_profit = 0 | |
for i in range( 1 , len ( prices ) ) : | |
previous_delta = delta | |
delta = prices[ i ] - prices [ i - 1 ] | |
if previous_delta > 0 : | |
delta += previous_delta | |
if max_profit < delta : | |
max_profit = delta | |
return max_profit | |
n = int( input() ) | |
for i in range ( n ): | |
print ( maxProfit ( None, [ int(x) for x in input().split(' ') ] ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment