力扣 —— Two Sum ( 两数之和) python实现
2024-08-25 23:41:46
题目描述:
中文:
给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。
你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。
英文:
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
dict= {}
for i in range(0,len(nums)):
if nums[i] in dict :
return dict[nums[i]] ,i
else :
dict[target - nums[i]] = i
题目来源:力扣
最新文章
- Button--防止button多次点击
- 用 eric6 与 PyQt5 实现python的极速GUI编程(系列01)--Hello world!
- 【上手centos】一、前情以及sublime_text_3安装
- django上传图片和文字记录
- Hbase之批量数据写入
- PHP - PDO 之 mysql 事务功能
- 获取datagrid中编辑列combobox的value值与text值
- ​C语言数组作为函数参数
- Oracle存储过程的一点使用总结
- Blackboard - 百度百科
- Eclipse的WorkingSet使用(转载)
- Mybatis (一)
- sublimeText3 中配置sass环境,并将编译后文件保存到指定文件夹
- neutron基础一(网络基本命令)基本命令,包括veth peer
- 嵌入式开发平台迅为iTOP-4412开发板-ssh常见问题以及解决方法
- quick-cocos2d-x lua框架解析(一)对UI进行操作的UiUtil脚本
- Emacs 番茄钟 pomidor
- dd-wrt 中继配置
- 关于将vector以及string传递给较老的api的问题
- LR 解压缩函数(wgzMemDecompressBuffer)失败 Code=-5
热门文章
- Center os 用户环境变量
- ThreadPoolExecutor扩展
- 【leetcode】564. Find the Closest Palindrome
- boost unordered
- 【FTP】FTP(文件传输协议)工作原理(SFTP)
- 阿里云基于OSS的云上统一数据保护方案2.0技术解析
- Debug模式自定义NSlog
- SSM - 全局跨域处理
- error C2065: ‘_bstr_t’ : undeclared identifier
- CSS-多行超出隐藏