nums
and an integer target
, return indices of the two numbers such that they add up to target
. exatly one solution
, and you may not use the same element twice.o(n^2)
time complexity?# leetcode, easy : two sum, python3
# array, hash table
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
for x in range(len(nums)):
for y in range(x+1, len(nums)):
if nums[x] + nums[y] == target:
return [x, y]