how to sum two numbers in a list?

后端 未结 7 1998
我寻月下人不归
我寻月下人不归 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:41

    This question has 2 parts:

    1. Retrieving the 2 items in a list which equate to the target
    2. Retrieving their index value

      def get_index_for_target(nums, target):

      for x in nums:
          for y in nums:
              if x + y == target:
                  return (nums.index(x), nums.index(y))
      

提交回复
热议问题