leetcode刷题记录two sum

class Solution(object):
    def twoSum(self, nums, target):
        result = []
        for i in range(0,len(nums)):
            oneNum = nums[i]
            twoNum  = target - oneNum
            if twoNum in nums:
                j = nums.index(twoNum)
                if i != j:
                    result.append(i)
                    result.append(j)
                    return result
Given nums = [2, 7, 11, 15], target = 9,

Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页