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

Commit870e028

Browse files
best time to buy and sell stock II
1 parent31f38f3 commit870e028

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
packagemedium;
2+
3+
publicclassBestTimeToBuyAndSellStockII {
4+
5+
/**It turns out to be a super simple one, it's really a greedy one! Just keep being greedy if it's possible.*/
6+
publicintmaxProfit(int[]prices) {
7+
intpro =0;
8+
for(inti =0;i <prices.length-1;i++){
9+
if(prices[i+1] >prices[i])pro +=prices[i+1] -prices[i];
10+
}
11+
returnpro;
12+
}
13+
14+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp