We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ac812fc commit 415d29dCopy full SHA for 415d29d
Dynamic Programming/buy and sell stock 1
@@ -0,0 +1,17 @@
1
+// link : https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
2
+
3
4
5
+//space optimised
6
+int maxProfit(vector<int>& prices) {
7
+ int ma=0;
8
+ int ans=0;
9
+ int mi=prices[0];
10
+ int n=prices.size();
11
+ for(int i=1;i<n;i++){
12
+ ma=prices[i];
13
+ ans=max(ans,ma-mi);
14
+ mi=min(mi,prices[i]);
15
+ }
16
+ return ans;
17
+}
0 commit comments