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 05a50ec commit dceb7c6Copy full SHA for dceb7c6
best-time-to-buy-and-sell-stock/mintheon.java
@@ -0,0 +1,17 @@
1
+class Solution {
2
+ /**
3
+ 시간복잡도: O(n)
4
+ 공간복잡도: O(1)
5
+ */
6
+ public int maxProfit(int[] prices) {
7
+ int buyPrice = prices[0];
8
+ int maxProfit = 0;
9
+
10
+ for(int i = 0; i < prices.length; i++) {
11
+ buyPrice = Math.min(buyPrice, prices[i]);
12
+ maxProfit = Math.max(maxProfit, prices[i] - buyPrice);
13
+ }
14
15
+ return maxProfit;
16
17
+}
0 commit comments