【Leetcode-算法-Python3】1. 两数之和

class Solution(object):
    def twoSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
        for i,item in enumerate(nums):
            b=target-item
            if b in nums:
                j=nums.index(b)
                if i!=j:

                    return [i,j]

执行用时:1388 ms

猜你喜欢

转载自blog.csdn.net/aawsdasd/article/details/80484795
今日推荐