Skip to content

Commit 99cdc93

Browse files
Merge pull request #457 from Ayush-k-Shukla/patch-1
Create buy and sell stock 1
2 parents 85c1db0 + 415d29d commit 99cdc93

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)