Skip to content

Commit c9aa7dd

Browse files
committed
Best Time to Buy And Sell Stock solution
1 parent f96fa50 commit c9aa7dd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
int maxProfit(vector<int>& prices) {
4+
int min = INT_MAX;
5+
int profit = 0;
6+
7+
for(int i = 0; i < prices.size(); i++){
8+
if(prices[i] < min)
9+
min = prices[i];
10+
11+
profit = max(profit, prices[i] - min);
12+
}
13+
14+
return profit;
15+
}
16+
};

0 commit comments

Comments
 (0)