We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cacd05e commit d69facbCopy full SHA for d69facb
best-time-to-buy-and-sell-stock/sangyyypark.java
@@ -0,0 +1,22 @@
1
+/**
2
+
3
+ 최대이익 = 최고금액 - 최소금액
4
+ */
5
+class Solution {
6
+ public int maxProfit(int[] prices) {
7
+ int minPrice = Integer.MAX_VALUE;
8
+ int maximumProfit = 0;
9
10
+ for(int price : prices) {
11
+ if(price < minPrice) {
12
+ minPrice = price;
13
+ }
14
+ int currentProfit = price - minPrice;
15
+ if(currentProfit > maximumProfit) {
16
+ maximumProfit = currentProfit;
17
18
19
+ return maximumProfit;
20
21
+}
22
0 commit comments