Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created January 3, 2018 15:33
Show Gist options
  • Save s4553711/f4af659e7724754aa4a6ac923637ea70 to your computer and use it in GitHub Desktop.
Save s4553711/f4af659e7724754aa4a6ac923637ea70 to your computer and use it in GitHub Desktop.
class Solution {
public:
int maxProfit(vector<int>& prices) {
if (prices.size() <= 1) return 0;
int cum = 0;
for(int i = 1; i < prices.size(); i++) {
cum += (prices[i] > prices[i-1] ? prices[i] - prices[i-1] : 0);
}
return cum;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment