Skip to content

Instantly share code, notes, and snippets.

@XcqRomance
Created December 3, 2018 07:07
Show Gist options
  • Save XcqRomance/d17baff2d0a5cc7df1e9707a34503465 to your computer and use it in GitHub Desktop.
Save XcqRomance/d17baff2d0a5cc7df1e9707a34503465 to your computer and use it in GitHub Desktop.
2.买卖股票的最佳时机 II
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