Created
January 3, 2018 15:33
-
-
Save s4553711/f4af659e7724754aa4a6ac923637ea70 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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