贪心
leetcode 122. 买卖股票的最佳时机 II
典型贪心
class Solution {
public:
int maxProfit(vector<int>& prices) {
int maxProf = 0;
if (prices.size() == 1) {
return 0;
}
for (int i = 1; i < prices.size(); i++) {
maxProf += max(0, (prices[i] - prices[i-1]));
}
return maxProf;
}
};