力扣算法题

1. 两数之和

nums = [2,7,11,13,15]
target = 26

class Solution(object):
    def twoSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
        dic = {}
        # i为索引,t为列表元素
        for i,t in enumerate(nums):
            if (target - t) in dic:
                return [i, dic[target - t]]
            dic[t] = i

obj = Solution()
print(obj.twoSum(nums,target))

2. 两数相加

3. 无重复字符的最长子串

4. 寻找两个有序数组的中位数

5. 最长回文子串

posted @ 2020-04-07 18:42  lvweihe  阅读(424)  评论(0编辑  收藏  举报