fixed numbering and went back to complete challenge 26
This commit is contained in:
parent
07a918bcb0
commit
7945da491a
19
Top150Interview/122BestTimetoBuyandSellStock2.py
Normal file
19
Top150Interview/122BestTimetoBuyandSellStock2.py
Normal file
@ -0,0 +1,19 @@
|
||||
def maxProfit(prices):
|
||||
"""
|
||||
:type prices: List[int]
|
||||
:rtype: int
|
||||
"""
|
||||
lowest = min(prices)
|
||||
if lowest == prices[len(prices)-1]:
|
||||
print('no profit')
|
||||
return 0
|
||||
for i in range(len(prices)):
|
||||
if lowest == prices[i]:
|
||||
k = i+1
|
||||
# print(f'k is {k}')
|
||||
profit = max(prices[k:]) - lowest
|
||||
print(profit)
|
||||
return profit
|
||||
|
||||
maxProfit([7,1,5,3,6,4])
|
||||
# maxProfit([7,6,4,3,1])
|
||||
5
Top150Interview/26RemoveDuplicatesFromSortedArray.py
Normal file
5
Top150Interview/26RemoveDuplicatesFromSortedArray.py
Normal file
@ -0,0 +1,5 @@
|
||||
def removeDuplicates(self, nums):
|
||||
"""
|
||||
:type nums: List[int]
|
||||
:rtype: int
|
||||
"""
|
||||
Loading…
Reference in New Issue
Block a user