Created
July 22, 2017 10:25
-
-
Save nerohoop/0f2155f665a4a95291c5bc83d3ddc544 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
int maxRight[size-1]; | |
maxRight[size-2] = price[size-1]; | |
for(int i=size-3; i>=0; i--) { | |
maxRight[i] = MAX(price[i+1], maxRight[i+1]); | |
} | |
long long profit = 0; | |
for(int i=0; i<size-1; i++) { | |
if(maxRight[i] > price[i]) { | |
profit += maxRight[i] - price[i]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment