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 9416914

Browse files
Added solution for the Best Time to Buy and Sell Stock problem
Signed-off-by: Krishna Kishore Shetty <kkshetty.work@pm.me>
1 parent 07a6efa commit 9416914

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def maxProfit(self, prices: List[int]) -> int:
3+
max_profit = 0
4+
buy_price = 999999999
5+
6+
for price in prices:
7+
if price<buy_price:
8+
buy_price=price
9+
continue
10+
11+
if price>buy_price:
12+
max_profit = max(max_profit, price-buy_price)
13+
14+
return max_profit

0 commit comments

Comments
(0)

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