diff --git a/Improved best time to buy stocks b/Improved best time to buy stocks new file mode 100644 index 0000000..321841a --- /dev/null +++ b/Improved best time to buy stocks @@ -0,0 +1,15 @@ +class Solution { +public: + int maxProfit(vector& prices) { + int minPrice = INT_MAX; + int maxProf = 0; + for(int i = 0; i < prices.size(); i++) + { + minPrice = min(minPrice, prices[i]); + maxProf = max(maxProf, prices[i] - minPrice); + } + return maxProf; + } +}; + +// https://leetcode.com/problems/best-time-to-buy-and-sell-stock/submissions/