From 0ff4bddd83d2d6ece4c05b77e63476ce92876b88 Mon Sep 17 00:00:00 2001 From: mhdnihas Date: Thu, 1 May 2025 15:43:47 +0530 Subject: [PATCH 1/3] Added solution for Two Sum --- challenge-1/two-sum.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 challenge-1/two-sum.py diff --git a/challenge-1/two-sum.py b/challenge-1/two-sum.py new file mode 100644 index 0000000..47f8d35 --- /dev/null +++ b/challenge-1/two-sum.py @@ -0,0 +1,15 @@ +class Solution(object): + def twoSum(self, nums, target): + """ + :type nums: List[int] + :type target: int + :rtype: List[int] + """ + hash_map={} + + for index in range(len(nums)): + if nums[index] in hash_map: + return [hash_map[nums[index]],index] + else: + hash_map[target-nums[index]]=index + From 8c97f8bd54ef183c5aba5e3ab37918bf0bdd5330 Mon Sep 17 00:00:00 2001 From: mhdnihas Date: Fri, 2 May 2025 21:54:03 +0530 Subject: [PATCH 2/3] Added solution for Two Sum --- Challenge-1/two-sum.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Challenge-1/two-sum.py diff --git a/Challenge-1/two-sum.py b/Challenge-1/two-sum.py new file mode 100644 index 0000000..47f8d35 --- /dev/null +++ b/Challenge-1/two-sum.py @@ -0,0 +1,15 @@ +class Solution(object): + def twoSum(self, nums, target): + """ + :type nums: List[int] + :type target: int + :rtype: List[int] + """ + hash_map={} + + for index in range(len(nums)): + if nums[index] in hash_map: + return [hash_map[nums[index]],index] + else: + hash_map[target-nums[index]]=index + From 4dbe28e4496dc38e48e75baec12e95bc0878067a Mon Sep 17 00:00:00 2001 From: mhdnihas Date: Fri, 2 May 2025 23:04:58 +0530 Subject: [PATCH 3/3] Added solution for Best Time to Buy and Sell Stock --- Challenge-2/Best-Time-to-Buy-and-Sell-Stock.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Challenge-2/Best-Time-to-Buy-and-Sell-Stock.py diff --git a/Challenge-2/Best-Time-to-Buy-and-Sell-Stock.py b/Challenge-2/Best-Time-to-Buy-and-Sell-Stock.py new file mode 100644 index 0000000..8161211 --- /dev/null +++ b/Challenge-2/Best-Time-to-Buy-and-Sell-Stock.py @@ -0,0 +1,16 @@ +class Solution(object): + def maxProfit(self, prices): + """ + :type prices: List[int] + :rtype: int + """ + max_profit=0 + minimum=prices[0] + for i in range(1,len(prices)): + if prices[i]>minimum: + max_profit=max(max_profit,prices[i]-minimum) + else: + minimum=prices[i] + return max_profit + +