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)]

相关推荐
KingRumn5 小时前
Linux信号之标准信号与实时信号
linux·算法
源代码•宸8 小时前
Leetcode—620. 有趣的电影&&Q3. 有趣的电影【简单】
数据库·后端·mysql·算法·leetcode·职场和发展
2301_800256119 小时前
地理空间数据库中的CPU 和 I/O 开销
数据库·算法·oracle
一个不知名程序员www9 小时前
算法学习入门---结构体和类(C++)
c++·算法
阿亮爱学代码11 小时前
Java 面试 (三)
面试·职场和发展
XFF不秃头12 小时前
力扣刷题笔记-旋转图像
c++·笔记·算法·leetcode
王老师青少年编程12 小时前
csp信奥赛C++标准模板库STL案例应用3
c++·算法·stl·csp·信奥赛·lower_bound·标准模版库
有为少年13 小时前
Welford 算法 | 优雅地计算海量数据的均值与方差
人工智能·深度学习·神经网络·学习·算法·机器学习·均值算法
Ven%13 小时前
从单轮问答到连贯对话:RAG多轮对话技术详解
人工智能·python·深度学习·神经网络·算法