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.
# author:wei
class Solution:
def twoSum(self,list,target):
for j in range(len(list)-1):
if target==list[j]+list[j+1]:
print(j,j+1)
a=Solution()
a.twoSum([1,2,3,4,7,100,6,356,24,56,44],100)
本文介绍了一个经典的算法问题——寻找数组中两个数相加等于特定目标值的索引。该问题要求不能重复使用相同的元素,并且确保每个输入都有唯一解。通过一个简单的Python实现示例展示了如何解决这个问题。
408

被折叠的 条评论
为什么被折叠?



