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 ...
随机推荐
- 【转】C#自定义控件:WinForm将其它应用程序窗体嵌入自己内部
PS:文末的附件已更新,这次我放到博客园里面了,不会弹出广告,放心下载,O(∩_∩)O谢谢! 这是最近在做的一个项目中提到的需求,把一个现有的窗体应用程序界面嵌入到自己开发的窗体中来,看起来就像自己开 ...
- DevExpress]ChartControl 创建Drill-Down样式的Title
关键代码: /// <summary> /// 创建Drill-Down样式的Title /// </summary> /// <param name="cha ...
- js——事件
焦点:使浏览器能够区分用户输入的对象,当一个元素有焦点的时候,那么他就可以接收用户的输入. 我们可以通过一些方式给元素设置焦点 1.点击 2.tab 3.js 不是所有元素都能够接收焦点的.能够响应用 ...
- JVM结构、GC工作机制详解(转)
原文地址:http://blog.csdn.NET/tonytfjing/article/details/44278233 JVM结构.内存分配.垃圾回收算法.垃圾收集器.下面我们一一来看. 一.JV ...
- NOIP2012模拟试题【圆圈舞蹈( circle)
2.圆圈舞蹈( circle) [问题描述] 熊大妈的奶牛在时针的带领下,围成了一个圆圈跳舞.由于没有严格的教育,奶牛们之间的间隔不一致. 奶牛想知道两只最远的奶牛到底隔了多远.奶牛A到B的距离为A顺 ...
- php代码20个实用技巧 ------ 转发自菜鸟教程
1.不要实用相对路径 常常会看到: require_once('../../lib/some_class.php'); 该方法有很多缺点:它首先查找指定的php包含路径,然后查找当前目录,因此会检查过 ...
- 基于位运算符的IP和数值转换
直接上代码: $str = '192.168.2.100'; echo 'IP:',$str,'<hr />'; $int = ip_long($str); echo $int,'< ...
- AndroidManifest.xml配置文件详解
AndroidManifest.xml配置文件对于Android应用开发来说是非常重要的基础知识,本文旨在总结该配置文件中重点的用法,以便日后查阅.下面是一个标准的AndroidManifest.xm ...
- hl7 java 解析
原文链接 http://blog.csdn.net/ycyangcai/article/details/6643784 Hl7引擎的目标主要是解决将数据按HL7协议的要求标准化,和标准业务的集成和不同 ...
- 21. 无法执行该操作,因为链接服务器”Server_202”的 OLE DB 访问接口 “SQLNCLI10″ 无法启动分布式事务”
无法执行该操作,因为链接服务器”Server_202”的 OLE DB 访问接口 “SQLNCLI10″ 无法启动分布式事务” 原因:调用存储过程的方式有问题,必须用JDBC方式调用存储过程才可以正常 ...