From ff40e7ffde3913cf418a22a75649887c8f81c200 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 5 Dec 2024 03:13:00 +0000 Subject: [PATCH] =?UTF-8?q?=EC=9D=B4=EC=8A=88=20#445=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=86=94=EB=A3=A8=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LeetCode/Best_Time_to_Buy_and_Sell_Stock_II.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 LeetCode/Best_Time_to_Buy_and_Sell_Stock_II.cpp 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