Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb25a834

Browse files
refactor 122
1 parent414977f commitb25a834

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

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

2424
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.
31+
*/
2632
publicintmaxProfit(int[]prices) {
2733
intpro =0;
2834
for (inti =0;i <prices.length -1;i++) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp