LeetCode 122. Best Time to Buy and Sell Stock II
Solution1:我的答案
贪心和DP傻傻分不清!
class Solution {
public:
int maxProfit(vector<int>& prices) {
int max_pro = 0, n = prices.size();
if (!n) return max_pro;
int dp[n];
dp[0] = 0;
for (int i = 1; i < n; i++) {
dp[i] = max(prices[i] - prices[i-1], 0);
max_pro += dp[i];
}
return max_pro;
}
};