We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 412bf7b commit ed2c4c4Copy full SHA for ed2c4c4
โbest-time-to-buy-and-sell-stock/hi-rachel.py
@@ -0,0 +1,26 @@
1
+# TC: O(N), SC: O(1)
2
+
3
+class Solution:
4
+ def maxProfit(self, prices: List[int]) -> int:
5
+ max_profit = 0
6
+ min_price = prices[0]
7
8
+ for price in prices:
9
+ max_profit = max(price - min_price, max_profit)
10
+ min_price = min(price, min_price)
11
+ return max_profit
12
13
+# TS ํ์ด
14
+# ๋ฐฐ์ด ์์(์ซ์๊ฐ)์ ์ง์ ์ํํ๋ ค๋ฉด for ... of ์ฌ์ฉ ํน์ forEach
15
+# for ... in -> ์ธ๋ฑ์ค๋ฅผ ๊ฐ์ ธ์ด
16
17
+# function maxProfit(prices: number[]): number {
18
+# let max_profit: number = 0;
19
+# let min_price: number = prices[0];
20
21
+# for (let price of prices) {
22
+# max_profit = Math.max(max_profit, price - min_price);
23
+# min_price = Math.min(min_price, price);
24
+# }
25
+# return max_profit;
26
+# };
0 commit comments