# Best Time to Buy and Sell Stock ## Programming Language: C++ ### Back to [Leetcode Blind 75 Practice Note](/xh5b5HXPTHGz_jwwymNKlw) [Leetcode: Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description//) 看別人[解答](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/solutions/3914105/most-optimized-solution-easy-to-understand-c-java-python)才會 ```c++= class Solution { public: int maxProfit(vector<int>& prices) { int min_price = prices[0]; int maxprof = 0; for(int i=1;i<prices.size();i++){ maxprof = max(maxprof,prices[i]-min_price); min_price = min(prices[i],min_price); } return maxprof; } }; ``` 這次學會兩個新的STD 1. max(): [mac()教學](https://shengyu7697.github.io/std-max/) 2. min(): [min()教學](https://shengyu7697.github.io/std-min/)