You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/java/com/fishercoder/solutions/_122.java
+7-1Lines changed: 7 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,13 @@ public int maxProfit(int[] prices) {
22
22
}
23
23
24
24
publicstaticclassSolution2 {
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.