leetcode two sum python
class Solution:
# @param {integer[]} nums
# @param {integer} target
# @return {integer[]}
def twoSum(self, nums, target):
intLen=len(nums)
if intLen <=1:
return False
res=[]
dicts={}
for i in range(0,intLen):
if not dicts.has_key(target-nums[i]):
dicts[nums[i]]=i
else:
tmpIndex=target-nums[i]
res.append(dicts[tmpIndex]+1)
res.append(i+1)
return res
leetcode two sum python的更多相关文章
- [leetcode]Path Sum @ Python
原题地址:https://oj.leetcode.com/problems/path-sum/ 题意: Given a binary tree and a sum, determine if the ...
- leetcode Combination Sum python
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...
- LeetCode:Path Sum I II
LeetCode:Path Sum Given a binary tree and a sum, determine if the tree has a root-to-leaf path such ...
- 剑指offer 65. 不用加减乘除做加法(Leetcode 371. Sum of Two Integers)
剑指offer 65. 不用加减乘除做加法(Leetcode 371. Sum of Two Integers) https://leetcode.com/problems/sum-of-two-in ...
- [LeetCode]题解(python):113 Path Sum II
题目来源 https://leetcode.com/problems/path-sum-ii/ Given a binary tree and a sum, find all root-to-leaf ...
- [LeetCode]题解(python):112 Path Sum
题目来源 https://leetcode.com/problems/path-sum/ Given a binary tree and a sum, determine if the tree ha ...
- [LeetCode]题解(python):064-Minimum Path Sum
题目来源 https://leetcode.com/problems/minimum-path-sum/ Given a m x n grid filled with non-negative num ...
- [LeetCode]题解(python):124-Binary Tree Maximum Path Sum
题目来源: https://leetcode.com/problems/binary-tree-maximum-path-sum/ 题意分析: 给定一棵树,找出一个数值最大的路径,起点可以是任意节点或 ...
- [LeetCode]题解(python):040-Combination Sum II
题目来源 https://leetcode.com/problems/combination-sum-ii/ Given a collection of candidate numbers (C) a ...
随机推荐
- usb键鼠标驱动分析
一.鼠标 linux下的usb鼠标驱动在/drivers/hid/usbhid/usbmouse.c中实现 1.加载初始化过程 1.1模块入口 module_init(usb_mouse_init); ...
- POJ1042 Gone Fishing
采用贪心策略. 假设他从1湖泊走到x 湖泊,这还剩下 h*12 - sigma(T1--Tx-1).(单位时间为5分钟).然后再用剩下的时间去钓1-x的湖泊的鱼. 每次都选择最多鱼的湖泊钓. code ...
- Jackson 框架,轻易转换JSON【转】
Jackson 框架,轻易转换JSON Jackson可以轻松的将Java对象转换成json对象和xml文档,同样也可以将json.xml转换成Java对象. 前面有介绍过json-lib这个框架,在 ...
- PHP+jQuery实现翻板抽奖
翻板抽奖的实现流程:前端页面提供6个方块,用数字1-6依次表示6个不同的方块,当抽奖者点击6个方块中的某一块时,方块翻转到背面,显示抽奖中奖信息.看似简单的一个操作过程,却包含着WEB技术的很多知识面 ...
- vs快捷键
Ctrl+E,D ----格式化全部代码 Ctrl+A+K+FCtrl+E,F ----格式化选中的代码 Ctrl+K+FCTRL + SHIFT + B生成解决方案 Alt+B+B 或 F6 生成当 ...
- oracle update语句的几点写法
update两表关联的写法包括字查询 1.update t2 set parentid=(select ownerid from t1 where t1.id=t2.id); 2. update tb ...
- SQL 字段里有逗号隔开的数据的取值
table 1 : id code1 0012 001,0023 001,002,003 table 2:code name001 数学002 体育003 美术 要求结果 id name1 数学2 数 ...
- C#根据汉字生成拼音首字母全称
static void Main(string[] args) { string s = GetChineseSpell("周杰伦"); Console.WriteLine(s.T ...
- /-- Encapsulated exception ------------\ java.lang.NoSuchMethodException: com.sjzdaj.po.Class.setN_id([Ljava.lang.String;)
转自:http://ruinxdgzy.iteye.com/blog/805138
- Fedora、CentOS install TTF/otf fonts
Step 1:切换至字体下载目录: [Richard@localhost Downloads]$ ll | grep otf -rw-rw-r--. Richard Richard 7月 RBNo2L ...