本文主要是介绍代码随想录 Leetcode122. 买卖股票的最佳时机 II,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:
代码(首刷自解 2024年2月9日):
class Solution {
public:int maxProfit(vector<int>& prices) {int res = 0;for (int i = 1; i < prices.size(); ++i) {if (prices[i] - prices[i - 1] > 0) {res += prices[i] - prices[i - 1];} else {continue;}}return res;}
};
这篇关于代码随想录 Leetcode122. 买卖股票的最佳时机 II的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!