Skip to content

Commit eebb5f3

Browse files
authored
Add LeetCode - 121 solution in C (#62)
* Add solution to LeetCode 112 * Address requested changes * Add leetcode 1 (nlogn approach) and leetcode 167 * Address requested changes * Fix indentation * Add LeetCode 121 solution in C
1 parent 5d6c8f5 commit eebb5f3

File tree

1 file changed

+13
-0
lines changed
  • Algorithms/Easy/121_BestTimeToBuyAndSellStock

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
int maxProfit(int* prices, int pricesSize){
2+
int answer = 0;
3+
int buyingPrice = prices[0];
4+
5+
for(int i = 1; i < pricesSize; i++){
6+
if(prices[i] < buyingPrice)
7+
buyingPrice = prices[i];
8+
else if (prices[i] - buyingPrice > answer)
9+
answer = prices[i] - buyingPrice;
10+
}
11+
12+
return answer;
13+
}

0 commit comments

Comments
 (0)