#NEWLINE# def maxProfitDelta( self , prices ) : #NEWLINE# #INDENT# '\n        Only long position allowed, cannot short\n\n        Algorithm: max-array problem\n\n        convert to maximum sub-array problem\n        two pointer\n\n        :param prices: a list of integer\n        :return: integer, max profit\n        ' #NEWLINE# if ( len ( prices ) <= 1 ) : #NEWLINE# #INDENT# return 0 #NEWLINE# #UNINDENT# delta_prices = [ ] #NEWLINE# for i in xrange ( 1 , len ( prices ) ) : #NEWLINE# #INDENT# delta_prices . append ( ( prices [ i ] - prices [ ( i - 1 ) ] ) ) #NEWLINE# #UNINDENT# max_sub_array = 0 #NEWLINE# current_sub_array = 0 #NEWLINE# for j in xrange ( len ( delta_prices ) ) : #NEWLINE# #INDENT# current_sub_array = max ( 0 , ( current_sub_array + delta_prices [ j ] ) ) #NEWLINE# max_sub_array = max ( max_sub_array , current_sub_array ) #NEWLINE# #UNINDENT# return prices