记录自己leetCode做的算法题
1、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 sameelement twice.
Example:
Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1].
def towSum(nums,target):
indice=0
flag=True
while flag:
length = len(nums)
if length>1:
a=nums.pop(0)
indice += 1
if length==1:
print('无法计算得出target' %target)
break
for i in range(len(nums)):
if nums[i] + a==target:
print('计算得出的下标是%s、%s,值分别是%s+%s=%s'% (indice-1,i+indice,a,nums[i],target))
flag=False
break
towSum([1,2,3,4,5,8,9],13)