Skip to content
13 changes: 13 additions & 0 deletions Algorithms/Easy/121_BestTimeToBuyAndSellStock/Solution.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
int maxProfit(int* prices, int pricesSize){
int answer = 0;
int buyingPrice = prices[0];

for(int i = 1; i < pricesSize; i++){
if(prices[i] < buyingPrice)
buyingPrice = prices[i];
else if (prices[i] - buyingPrice > answer)
answer = prices[i] - buyingPrice;
}

return answer;
}