leetcode 热题100 两数之和

class Solution(object):

def twoSum(self, nums, target):

"""

:type nums: Listint

:type target: int

:rtype: Listint

"""

myDict = {}

for i,t in enumerate(nums):

myDictnums\[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)

相关推荐
lsylalalala12 分钟前
常见的排序算法1
数据结构·算法·排序算法
想吃火锅10051 小时前
【leetcode】54. 螺旋矩阵
算法·leetcode·矩阵
想吃火锅10051 小时前
【leetcode】300. 最长递增子序列
算法·leetcode·职场和发展
imaol11 小时前
数据结构---队列
java·数据结构·算法
数模竞赛Paid answer1 小时前
2026年电工杯数学建模A题绿电直连型电氢氨园区优化运行求解全过程论文及程序
算法·数学建模·电工杯
疯狂打码的少年1 小时前
【数据结构】串的模式匹配:KMP算法(重点)
数据结构·笔记·算法
Dr.kangder2 小时前
嵌入式面试总结(八)——大小端
嵌入式硬件·面试·职场和发展·架构·嵌入式
晚风醉蝶2 小时前
第零篇-算法全景图
算法
疯狂打码的少年3 小时前
【数据结构】树的基本概念与二叉树定义
java·数据结构·笔记·算法
webmote333 小时前
用 NVIDIA Nemotron 3 Super + .NET 构建有记忆的多轮对话
后端·算法