Skip to content

Commit 1dd83e6

Browse files
committed
feat: add 0221 Best Time to Buy And Sell Stock solution
1 parent fbf5c6f commit 1dd83e6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def maxProfit(self, prices: List[int]) -> int:
3+
dp = [0] * (len(prices) + 1)
4+
least_num = prices[0]
5+
for i in range(len(prices)):
6+
least_num = min(prices[i], least_num)
7+
dp[i] = max(prices[i] - least_num, dp[i-1])
8+
return max(dp)

0 commit comments

Comments
 (0)