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 3569f0c commit 24a6c67Copy full SHA for 24a6c67
1 file changed
best-time-to-buy-and-sell-stock/freemjstudio.py
@@ -0,0 +1,21 @@
1
+# first attempt - time out
2
+
3
+class Solution:
4
+ def maxProfit(self, prices: List[int]) -> int:
5
+ max_profit = 0
6
+ for i in range(len(prices)):
7
+ profit = max(prices[i:]) - prices[i]
8
+ max_profit = max(max_profit, profit)
9
+ return max_profit
10
11
+# second attempt - greedy approach
12
13
14
15
+ min_price = prices[0]
16
17
18
+ min_price = min(min_price, prices[i])
19
+ profit = prices[i] - min_price
20
21
0 commit comments