From 7945da491a1ba2e7b760c1e6230c06f83e4a7420 Mon Sep 17 00:00:00 2001 From: ImAlpha Date: Wed, 28 Jun 2023 17:21:04 -0700 Subject: [PATCH] fixed numbering and went back to complete challenge 26 --- .../122BestTimetoBuyandSellStock2.py | 19 +++++++++++++++++++ .../26RemoveDuplicatesFromSortedArray.py | 5 +++++ ...{26RemoveElement.py => 27RemoveElement.py} | 0 3 files changed, 24 insertions(+) create mode 100644 Top150Interview/122BestTimetoBuyandSellStock2.py create mode 100644 Top150Interview/26RemoveDuplicatesFromSortedArray.py rename Top150Interview/{26RemoveElement.py => 27RemoveElement.py} (100%) diff --git a/Top150Interview/122BestTimetoBuyandSellStock2.py b/Top150Interview/122BestTimetoBuyandSellStock2.py new file mode 100644 index 0000000..655e173 --- /dev/null +++ b/Top150Interview/122BestTimetoBuyandSellStock2.py @@ -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]) \ No newline at end of file diff --git a/Top150Interview/26RemoveDuplicatesFromSortedArray.py b/Top150Interview/26RemoveDuplicatesFromSortedArray.py new file mode 100644 index 0000000..e43178f --- /dev/null +++ b/Top150Interview/26RemoveDuplicatesFromSortedArray.py @@ -0,0 +1,5 @@ +def removeDuplicates(self, nums): + """ + :type nums: List[int] + :rtype: int + """ \ No newline at end of file diff --git a/Top150Interview/26RemoveElement.py b/Top150Interview/27RemoveElement.py similarity index 100% rename from Top150Interview/26RemoveElement.py rename to Top150Interview/27RemoveElement.py