Created
December 3, 2018 07:07
-
-
Save XcqRomance/d17baff2d0a5cc7df1e9707a34503465 to your computer and use it in GitHub Desktop.
2.买卖股票的最佳时机 II
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 maxProfit(int* prices, int pricesSize) { | |
if (pricesSize <= 0) { | |
return 0; | |
} | |
int profit = 0; | |
for (int i = 0; i < pricesSize-1; i ++) { | |
if (prices[i+1] > prices[i]) { | |
profit += prices[i+1] - prices[i]; | |
} | |
} | |
return profit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment