class Solution:
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
cacls = nums[:]
cacls.sort()
for i in range(len(cacls) - 1):
for j in range(i + 1, len(cacls)):
if cacls[i] + cacls[j] == target:
head = nums.index(cacls[i])
tail = nums.index(cacls[j])
if head == tail:
tail = nums.index(cacls[j], head + 1)
ret = [head, tail]
ret.sort()
return ret
if cacls[i] + cacls[j] > target:
break
return []
def twoSum(nums, target):
data = dict()
for i in range(len(nums)):
if nums[i] not in data:
data[target - nums[i]] = i
else:
return [data[nums[i]], i]
return []