Skip to content

Commit 0b71f15

Browse files
committed
maxProfit
1 parent 7ffcfb9 commit 0b71f15

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

maxProfit.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def maxProfit(self, prices: List[int]) -> int:
3+
maxProfit = 0
4+
smallestNumber = prices[0]
5+
for i in range(len(prices)):
6+
if prices[i] < smallestNumber:
7+
smallestNumber = prices[i]
8+
else:
9+
newMax = prices[i] - smallestNumber
10+
if newMax > maxProfit:
11+
maxProfit = newMax
12+
return maxProfit

0 commit comments

Comments
 (0)