class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
here we can do brute force .
for i in range of len(nums) ;
target =[]
hashmap as dict here we are using it
hashmap ={} #here we are initializiing the dictionary
for i,num in enumerate(nums):
hashmap[num]=i
for i ,num in enumerate(nums):
x=target-num
if x in hashmap and hashmap[x] != i:
return [i,hashmap[x]]
return []
Written by nishan thapa
class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
here we can do brute force .
for i in range of len(nums) ;
target =[]
hashmap as dict here we are using it
"""
hashmap ={} #here we are initializiing the dictionary
for i,num in enumerate(nums):
hashmap[num]=i
for i ,num in enumerate(nums):
x=target-num
if x in hashmap and hashmap[x] != i:
return [i,hashmap[x]]
return []
hashmap ={} #here we are initializiing the dictionary
for i ,num in enumerate(nums):
x=target-num
if x in hashmap and hashmap[x] != i:
return [i,hashmap[x]]
hashmap[num]=i
return []