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 0383dda commit 8917da0Copy full SHA for 8917da0
โbest-time-to-buy-and-sell-stock/ohkingtaek.pyโ
@@ -0,0 +1,16 @@
1
+class Solution:
2
+ def maxProfit(self, prices: List[int]) -> int:
3
+ """
4
+ ์ง๊ธ๊น์ง ๋ณธ ๊ฐ๊ฒฉ ์ค ๊ฐ์ฅ ์์ ๊ฐ์ ๊ณ์ ์ ์ฅํ๊ณ
5
+ ํ์ฌ ๊ฐ๊ฒฉ์์ ๊ทธ ์ต์๊ฐ์ ๋บ ๊ฐ์ผ๋ก ์ต๋ ์ด์ต์ ๊ฐฑ์ ํฉ๋๋ค.
6
+ ํ ๋ฒ ์ํํ๋ฉด์ ์ต๋ profit์ ์ฐพ๋ ๋ฐฉ์์ ๋๋ค
7
8
+ min_price = float('inf')
9
+ max_profit = 0
10
+
11
+ for price in prices:
12
+ min_price = min(min_price, price)
13
+ max_profit = max(max_profit, price - min_price)
14
15
+ return max_profit
16
0 commit comments