leetcode 热题100 两数之和

class Solution(object):

def twoSum(self, nums, target):

"""

:type nums: List[int]

:type target: int

:rtype: List[int]

"""

myDict = {}

for i,t in enumerate(nums):

myDict[nums[i]] = i

for i,t in enumerate(nums):

tmp = target - t

if myDict.get(tmp)!=None and myDict.get(tmp)!=i:

return [i,myDict.get(tmp)]

相关推荐
序属秋秋秋6 分钟前
算法精讲【整数二分】(实战教学)
笔记·算法·二分查找
商bol4540 分钟前
习题与正则表达式
数据结构·c++·算法
LAOLONG-C2 小时前
从零到有的游戏开发(visual studio 2022 + easyx.h)
c语言·ide·算法·visual studio
机器鱼2 小时前
MATLAB基于统计特征与指数退化模型的风力发电机高速轴承剩余寿命预测
人工智能·算法·机器学习
clock的时钟3 小时前
数据结构(一)KMP+滑动窗口+链表+栈+队列
数据结构·算法·链表
sugar__salt3 小时前
各种排序思路及实现
数据结构·算法·排序算法
Vitalia3 小时前
⭐算法OJ⭐数据流的中位数【最小堆】Find Median from Data Stream
数据结构·c++·算法·最小堆
点我头像干啥3 小时前
机器学习中的聚类分析算法:原理与应用
人工智能·算法·机器学习
sml259(劳改版)3 小时前
子串分值和(蓝桥杯)
职场和发展·蓝桥杯
仟濹3 小时前
【C/C++】双指针与前缀和
c语言·c++·算法