The six Day 数组中找出和为目标值
作者:互联网
class Solution(object): """ 给定一个整数数组 nums 和一个目标值 target, 请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。 """ def twosum(nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ for i in range(len(nums)): for j in range(i+1, len(nums)): sum = nums[i] + nums[j] if sum == target: return i, j else: i += 1 if __name__ == '__main__': s = Solution() nums = [2, 7, 11, 15] target = 9 r = twosum(nums, target) print(r)
标签:__,target,nums,int,six,数组,目标值,Day 来源: https://www.cnblogs.com/jiyanjiao-702521/p/12612083.html