题目描述:

中文:

给定一个整数数组 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

题目来源:力扣

最新文章

  1. Button--防止button多次点击
  2. 用 eric6 与 PyQt5 实现python的极速GUI编程(系列01)--Hello world!
  3. 【上手centos】一、前情以及sublime_text_3安装
  4. django上传图片和文字记录
  5. Hbase之批量数据写入
  6. PHP - PDO 之 mysql 事务功能
  7. 获取datagrid中编辑列combobox的value值与text值
  8. ​C语言数组作为函数参数
  9. Oracle存储过程的一点使用总结
  10. Blackboard - 百度百科
  11. Eclipse的WorkingSet使用(转载)
  12. Mybatis (一)
  13. sublimeText3 中配置sass环境,并将编译后文件保存到指定文件夹
  14. neutron基础一(网络基本命令)基本命令,包括veth peer
  15. 嵌入式开发平台迅为iTOP-4412开发板-ssh常见问题以及解决方法
  16. quick-cocos2d-x lua框架解析(一)对UI进行操作的UiUtil脚本
  17. Emacs 番茄钟 pomidor
  18. dd-wrt 中继配置
  19. 关于将vector以及string传递给较老的api的问题
  20. LR 解压缩函数(wgzMemDecompressBuffer)失败 Code=-5

热门文章

  1. Center os 用户环境变量
  2. ThreadPoolExecutor扩展
  3. 【leetcode】564. Find the Closest Palindrome
  4. boost unordered
  5. 【FTP】FTP(文件传输协议)工作原理(SFTP)
  6. 阿里云基于OSS的云上统一数据保护方案2.0技术解析
  7. Debug模式自定义NSlog
  8. SSM - 全局跨域处理
  9. error C2065: ‘_bstr_t’ : undeclared identifier
  10. CSS-多行超出隐藏