[leetcode 001] 两数之和

给定一个整数数组 nums 和一个目标值 target,在该数组中找出和为目标值的两个整数,并返回他们的数组下标。

class Solution(object):
 def two_sum:
   """
  :type nums: List[int]

    :type target: int
    :rtype: List[int]

"""
   n=len(nums)
   for x in range(n):
      for y in range(x+1,n):
         if nums[y] == target - nums[x]:
              return x, y
   

 

posted on 2019-01-27 09:55  女士品茶  阅读(102)  评论(0编辑  收藏  举报