1. 程式人生 > >LeetCode 2Sum python

LeetCode 2Sum python

class Solution:
    def twoSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
        for x in nums:
            first_index=nums.index(x)
            nums[nums.index(x)]='push'
            if (target-x in nums):
                return [first_index,nums.index(target-x)]