Skip to content

Commit b25a834

Browse files
refactor 122
1 parent 414977f commit b25a834

File tree

1 file changed

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

1 file changed

+7
-1
lines changed

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ public int maxProfit(int[] prices) {
2222
}
2323

2424
public static class Solution2 {
25-
//simple one pass approach: the above solution could be simplied as below
25+
//simple one pass approach: the above solution could be simplified as below
26+
27+
/**
28+
* Or this approach could be understood as:
29+
* We'll sell and buy on the same day as long as this day's stock price is higher than the previous day, a good example is this array: [1, 2, 3, 4, 5].
30+
* As this problem states that:"you can buy it then immediately sell it on the same day". Likewise, we can buy it back immediately as we sell it on the same day.
31+
*/
2632
public int maxProfit(int[] prices) {
2733
int pro = 0;
2834
for (int i = 0; i < prices.length - 1; i++) {

0 commit comments

Comments
 (0)