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 cd835e1 commit eaeb2f9Copy full SHA for eaeb2f9
โbest-time-to-buy-and-sell-stock/Yn3-3xh.java
@@ -0,0 +1,23 @@
1
+/**
2
+[๋ฌธ์ ํ์ด]
3
+- ์์์๋ฅผ ๋๊ณ , ํฐ์์ ๋บ ๊ฐ์ ๊ตฌํ์.
4
+time: O(N), space: O(1)
5
+
6
+[ํ๊ณ ]
7
+์ด๋ฒ ๋ฌธ์ ๋ ๋์ด๋๊ฐ easy์ธ ๋๋ถ์ ๋ฌด๋ฆฌ์์ด ํ์๋ ๊ฒ ๊ฐ๋ค.
8
+ */
9
+class Solution {
10
+ public int maxProfit(int[] prices) {
11
+ int min = prices[0];
12
+ int max = 0;
13
+ for (int i = 1; i < prices.length; i++) {
14
+ if (min > prices[i]) {
15
+ min = prices[i];
16
+ continue;
17
+ }
18
+ max = Math.max(max, prices[i] - min);
19
20
+ return max;
21
22
+}
23
0 commit comments