Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b961d52

Browse files
committed
day-5
1 parent ff95e53 commit b961d52

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

‎best-time-to-buy-and-sell-stock.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def maxProfit(self, prices: List[int]) -> int:
3+
if not prices:
4+
return 0
5+
6+
profit = 0
7+
minimumStockValue = prices[0]
8+
9+
for i in range(len(prices)):
10+
if minimumStockValue > prices[i]:
11+
minimumStockValue = prices[i]
12+
profit = max((prices[i]-minimumStockValue),profit)
13+
return profit

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /