From c50da482de92b88e26de1bc37ade25a770800b9b Mon Sep 17 00:00:00 2001 From: Rahul Singh <94732146+rahulsingh5926@users.noreply.github.com> Date: Thu, 19 Oct 2023 12:51:17 +0530 Subject: [PATCH] Create Best Time to Buy and Sell Stock --- C++/Best Time to Buy and Sell Stock | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 C++/Best Time to Buy and Sell Stock diff --git a/C++/Best Time to Buy and Sell Stock b/C++/Best Time to Buy and Sell Stock new file mode 100644 index 00000000..e9a4d20c --- /dev/null +++ b/C++/Best Time to Buy and Sell Stock @@ -0,0 +1,19 @@ +class Solution { +public: +int diff=0; + int minElement=INT_MAX; + int maxProfit(vector& prices) { + for(int i=0;iminElement){ + diff=max(diff,prices[i]-minElement); + } + if(prices[i]