chaseleasy

chaseleasy
关注
44777 号成员,2019-04-02 11:33:34 加入
248
个人主页 浏览
9m44s
在线时长
  • [日常 LeetCode] 1.Two Sum

    2019-04-02 11:44

    class Solution:
    def twoSum(self, nums, target):
    """
    :type nums: List[int]
    :type target: int
    :rtype: List[int]
    """

        for i in nums:
            if nums.count(i)>1 and target == i*2 :
                start=nums.index(i)
                del nums[start]
                last=nums.index(i)+1
                return [start,last]
            if (target - i) in nums and (target-i) !=i:
                return [nums.index(i), nums.index(target - i)]
    

    只能击败 35% 的人