diff --git a/buy_and_sell_stocks/buy-sell-stocks.py b/buy_and_sell_stocks/buy-sell-stocks.py new file mode 100644 index 0000000..9a9c601 --- /dev/null +++ b/buy_and_sell_stocks/buy-sell-stocks.py @@ -0,0 +1,13 @@ +from typing import List + + +class Solution: + def maxProfit(self, prices: List[int]) -> int: + lowest_price = prices[0] + max_profit = 0 + for price in prices: + if price < lowest_price: + lowest_price = price + elif price - lowest_price > max_profit: + max_profit = price - lowest_price + return max_profit diff --git a/two-sum/two-sum.py b/two-sum/two-sum.py new file mode 100644 index 0000000..c3584a3 --- /dev/null +++ b/two-sum/two-sum.py @@ -0,0 +1,12 @@ +from typing import List + + +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + answer: List[int] = [] + for i in range(len(nums)): + for j in range(len(nums)): + if nums[i] + nums[j] == target and i != j: + answer.append(i) + answer.append(j) + return answer