【发布时间】:2017-09-14 12:47:48
【问题描述】:
** 如何打印返回 index1,index2?我尝试了不同的方法,但没有打印出来。 **
class Solution:
def twoSum(self, nums, target):
nums = [2,7,11,15]
target = 9
hash_map = {}
for index, value in enumerate(nums):
hash_map[value] = index
for index1, value in enumerate(nums):
if target - value in hash_map:
index2 = hash_map[target - value]
if index1 != index2:
return [index1,index2]
【问题讨论】:
-
您尝试了哪些不同的方法?编辑您的问题并包括这些尝试。
-
请编辑您的问题以包含您尝试过的Minimal, Complete, and Verifiable Example。
-
如果您有问题,最好现在添加或保持沉默。
标签: python python-3.x