how to sum two numbers in a list?

后端 未结 7 1915
我寻月下人不归
我寻月下人不归 2021-01-29 09:17

what is the solution of this by python 3 ?

Given an array of integers, return indices of the two numbers such that they add up to a spe

7条回答
  •  温柔的废话
    2021-01-29 09:36

    This function iterates through all the numbers in the list and finds the sum with other numbers. If the sum is equal to the target, it returns the indices

    def indices_sum(nums,target):
        for i in range(len(nums)):
            for j in range(i+1,len(nums)):
                if nums[i]+nums[j] == target: return(i,j)
    

提交回复
热议问题