diff --git a/LeetCode/Best_Time_to_Buy_and_Sell_Stock_II.cpp b/LeetCode/Best_Time_to_Buy_and_Sell_Stock_II.cpp new file mode 100644 index 0000000..7f83950 --- /dev/null +++ b/LeetCode/Best_Time_to_Buy_and_Sell_Stock_II.cpp @@ -0,0 +1,14 @@ +class Solution { +public: + int maxProfit(vector& prices) { + int profit = 0; + + for (int i = 1; i < prices.size(); i++) { + if (prices[i] > prices[i - 1]) { + profit += prices[i] - prices[i - 1]; + } + } + + return profit; + } +}; \ No newline at end of file