Skip to content

Commit 0bbc0d5

Browse files
Merge pull request #1945 from CodingTestStudy2/이진희
[이진희] Day33
2 parents c3887f2 + 56665a7 commit 0bbc0d5

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int maxProfit(int[] prices) {
3+
int minPrice = Integer.MAX_VALUE;
4+
int maxProfit = 0;
5+
6+
for (int price : prices) {
7+
if (price < minPrice) minPrice = price;
8+
else if (price - minPrice > maxProfit) maxProfit = price - minPrice;
9+
}
10+
11+
return maxProfit;
12+
}
13+
}

0 commit comments

Comments
 (0)