Skip to content

Commit 20ec744

Browse files
authored
Merge pull request #1262 from ivan1016017/may06
adding solution
2 parents 2aa0dd9 + d060d96 commit 20ec744

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from typing import List, Union, Collection, Mapping, Optional
2+
from abc import ABC, abstractmethod
3+
import math
4+
5+
class Solution:
6+
def maxProfit(self, prices: List[int]) -> int:
7+
8+
min_price = math.inf
9+
max_profit = 0
10+
len_prices = len(prices)
11+
12+
for i in range(len_prices):
13+
14+
if prices[i] < min_price:
15+
min_price = prices[i]
16+
elif prices[i] - min_price > max_profit:
17+
max_profit = prices[i] - min_price
18+
19+
return max_profit
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import unittest
2+
from src.my_project.interviews.top_150_questions_round_16\
3+
.best_time_to_sell_stock import Solution

0 commit comments

Comments
 (0)