From ee24690a28dbd4ef681d66d472bb63f908969479 Mon Sep 17 00:00:00 2001 From: mohdthajudeen Date: Sun, 20 Apr 2025 00:37:30 +0530 Subject: [PATCH 1/2] solution of two sum problem --- two-sum/two-sum.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 two-sum/two-sum.py 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 From 8b74756d6d728044026c4ec5b5ff3c59812c4dd2 Mon Sep 17 00:00:00 2001 From: mohdthajudeen Date: Sun, 20 Apr 2025 12:17:50 +0530 Subject: [PATCH 2/2] solution for maxProfit function for buy and sell stocks problem --- buy_and_sell_stocks/buy-sell-stocks.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 buy_and_sell_stocks/buy-sell-stocks.py 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