1
** 如何打印返回索引1,索引2?我嘗試不同的方式,但沒有打印出來。 **如何打印返回值?
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]
有哪些不同的方式,你試過嗎?編輯你的問題,幷包括這些嘗試。 –
請編輯您的問題,以包含您嘗試過的[最小,**完整**和可驗證示例](http://stackoverflow.com/help/mcve)。 –
如果您遇到問題,請立即添加或保持和平。 –