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

Commit d27296a

Browse files
committed
Time: 2 ms (63.52%), Space: 59.2 MB (42.39%) - LeetHub
1 parent 1566e99 commit d27296a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public int maxProfit(int[] prices) {
3+
int minTillNow = prices[0];
4+
int maxProfit = 0;
5+
for (int i = 1; i < prices.length; i++) {
6+
minTillNow = Math.min(minTillNow, prices[i]);
7+
maxProfit = Math.max(maxProfit, prices[i] - minTillNow);
8+
9+
}
10+
return maxProfit;
11+
}
12+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /