Skip to content

Commit

Permalink
이슈 #444에서 솔루션 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Dec 4, 2024
1 parent 5caef3b commit 9972c0a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions LeetCode/Best_Time_to_Buy_and_Sell_Stock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution {
public:
int maxProfit(vector<int>& prices) {
int minPrice = INT_MAX;
int maxProfit = 0;

for (int price : prices) {
maxProfit = max(maxProfit, price - minPrice);
minPrice = min(minPrice, price);
}

return maxProfit;
}
};

0 comments on commit 9972c0a

Please sign in to comment.