Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Challenge-1/two-sum.py
Original file line number Diff line number Diff line change
@@ -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

16 changes: 16 additions & 0 deletions Challenge-2/Best-Time-to-Buy-and-Sell-Stock.py
Original file line number Diff line number Diff line change
@@ -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


15 changes: 15 additions & 0 deletions challenge-1/two-sum.py
Original file line number Diff line number Diff line change
@@ -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