Leetcode 122. Best Time to Buy and Sell Stock II | | Leetcode 122. Best Time to Buy and Sell Stock II 文章作者:Tyan博客:noahsnail.com | CSDN | 简书 1. Description 2. Solution12345678910111213141516class Solution {public: int maxProfit(vector<int>& prices) { if(prices.size() == 0) { return 0; } int profit = 0; for(int i = 1; i < prices.size(); i++) { int diff = prices[i] - prices[i - 1]; if( diff > 0) { profit += diff; } } return profit; }}; Reference https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/description/ 如果有收获,可以请我喝杯咖啡! 赏 微信打赏 支付宝打赏