1. Two Sum-python
来源:互联网 发布:东方网络怎么了 编辑:程序博客网 时间:2024/05/21 15:46
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.
Example:Given nums = [2, 7, 11, 15], target = 9,Because nums[0] + nums[1] = 2 + 7 = 9,return [0, 1].
Code
class Solution: def twoSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ mydict={} rtnlist=[] i=0 for item in nums: if mydict.get(target-item)!=None: rtnlist.append(mydict[target-item]) rtnlist.append(i) else: mydict[item]=i i+=1 return rtnlist
阅读全文
2 0
- 1. Two Sum (python)
- 1. Two Sum-python
- 1.Two Sum Leetcode Python
- [Leetcode] 1.Two Sum @python
- 1. Two Sum [easy] (Python)
- LeetCode: 1. Two Sum python
- Leetcode: 1. Two Sum [python]
- [leetcode:python]1.Two Sum
- leetcode 1. Two Sum python
- LEETCODE 1.Two Sum (python实现)
- Leetcode题解(Python): 1.Two Sum
- 【Leetcode】【Python】【C++】1. Two Sum实现
- LeetCode 1.Two Sum (Python)
- 【leetcode】1. Two Sum(Python & C++)
- LeetCode 1. Two Sum Python Solution
- 【Leetcode】【python】Two Sum, Two Sum II
- LeetCodeOJ Two Sum (python)
- Two Sum(python)
- Java 运算符
- 一些计算机的基本概念
- Altera 综合开发平台 quartus的开发流程
- LINUX目录的读、写、执行权限的具体含义
- 树1
- 1. Two Sum-python
- Shell 输入/输出重定向
- spring-data-jpa中findOne与getOne的区别
- MyEclipse 8.5-svn插件的安装(附带插件网盘)
- leetcode 十一周解题报告
- 克隆创建PDB--(3)远程克隆NON-CDB创建PDB
- AngularJS
- 《Web接口开发与自动化测试基于Python语言》--第7章
- nginx配置文件讲解