The problem statement : Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
My solution(trying to do better than bruteforce approach):
def twoSum(nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
for i in range(0,len(nums)):
if (target - nums[i]) in nums.remove(nums[i]): #error
if i != nums.index(target - nums[i]):
return i, nums.index(target - nums[i])
I keep getting Line 9: TypeError: argument of type 'NoneType' is not iterable
.
I believe.remove()
returns a list and I am trying to check if target - nums[i]
is in the list.