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

相关推荐
ZPC82105 分钟前
【无标题】
人工智能·pytorch·算法·机器人
2301_764441337 分钟前
使用python构建的STAR实验ΛΛ̄自旋关联完整仿真
开发语言·python·算法
Rainy Blue88310 分钟前
前缀和与差分(蓝桥杯高频考点)
数据结构·算法·蓝桥杯
Dfreedom.10 分钟前
机器学习经典算法全景解析与演进脉络(无监督学习篇)
人工智能·学习·算法·机器学习·无监督学习
kaoshi100app16 分钟前
本周,河南二建报名公布!
开发语言·人工智能·职场和发展·学习方法
421!16 分钟前
ESP32学习笔记之GPIO
开发语言·笔记·单片机·嵌入式硬件·学习·算法·fpga开发
智算菩萨24 分钟前
【How Far Are We From AGI】4 AGI的“生理系统“——从算法架构到算力基座的工程革命
论文阅读·人工智能·深度学习·算法·ai·架构·agi
福赖27 分钟前
《算法:生产车间》
算法
alphaTao35 分钟前
LeetCode 每日一题 2026/3/16-2026/3/22
linux·windows·leetcode
空空潍35 分钟前
LeetCode力扣 hot100一刷完结
算法·leetcode