Skip to content

Commit fa073b4

Browse files
[N-0] refactor 121
1 parent b8ffb94 commit fa073b4

File tree

1 file changed

+7
-9
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+7
-9
lines changed

src/main/java/com/fishercoder/solutions/_121.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,28 @@
22

33
/**
44
* 121. Best Time to Buy and Sell Stock
5-
* <p>
5+
*
66
* Say you have an array for which the ith element is the price of a given stock on day i.
7-
* <p>
7+
*
88
* If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),
99
* design an algorithm to find the maximum profit.
10-
* <p>
10+
*
1111
* Example 1:
1212
* Input: [7, 1, 5, 3, 6, 4]
1313
* Output: 5
14-
* <p>
14+
*
1515
* max. difference = 6-1 = 5 (not 7-1 = 6, as selling price needs to be larger than buying price)
16-
* <p>
17-
* <p>
16+
*
17+
*
1818
* Example 2:
1919
* Input: [7, 6, 4, 3, 1]
2020
* Output: 0
21-
* <p>
21+
*
2222
* In this case, no transaction is done, i.e. max profit = 0.
2323
*/
2424

2525
public class _121 {
2626

27-
/**Pretty straightforward, sell before you buy, keep a global maxProfit variable, update it along the way if necessary.*/
28-
2927
/**
3028
* The key here is that you'll have to buy first, before you can sell.
3129
* That means, if the lower price comes after a higher price, their combination won't work! Since you cannot sell first

0 commit comments

Comments
 (0)