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 ...
随机推荐
- 关于oracle的certview
前两天去参加oracle 11g 的两门考试(1Z0-051和1Z0-052),在家看了好几遍题库,我本来想着上午一门,下午考一门,但是我嫌着麻烦,就预约一下午考完两门.在考试完一门后,发现成绩不 ...
- 【Stackoverflow好问题】Java += 操作符实质
问题 直到今天,我都一直以为: i += j 等同于 i = i + j; 但如果有: int i = 5; long j = 8; 这时 i = i + j不能编译.但i += j却能够编译.这说明 ...
- Android 它们的定义View (一)
转载请注明出处:http://blog.csdn.net/lmj623565791/article/details/24252901 非常Android入门程序员AndroidView.可能都是比較恐 ...
- 20141112 WinForm子窗口标签页
(一)标签页 先看看效果: 代码: public partial class 标签页 : Form { string s = ""; public 标签页() { Initiali ...
- windows下如何安装配置mysql-5.7-m14-winx64(zip格式的安装)
win7 64位下如何安装配置mysql-5.7.4-m14-winx64 1. mysql-5.7.4-m14-winx64.zip下载 官方网站下载地址:http://dev.mysql.co ...
- boost signal2 trackable
挺简单的一个类,只是维护了一个成员 shared_ptr<detail::trackable_pointee> _tracked_ptr; 这样看来的话,所谓的track还是基于智能指针, ...
- C++虚函数在内存中的实现
首先来一张图,一目了然: 然后把相应的代码贴上来: class A { int a; public: virtual void f(); virtual void g(int); virtual vo ...
- python 32位、64位确定
1.python 进入交互式命令行,如下: 2.执行以下命令: import struct;print struct.calcsize("P") * 8
- 从零开始PHP学习 - 第一天
写这个系列文章主要是为了督促自己 每天定时 定量消化一些知识! 同时也为了让需要的人 学到点啥~! 本人技术实在不高!本文中可能会有错误!希望大家发现后能提醒一下我和大家! 偷偷说下 本教程最后的目 ...
- CDC不同模式在ODI体现系列之二 异步模式
CDC不同模式在ODI体现系列之二 异步模式 2 异步模式需要在数据库中做一些准备工作: 改数据为归档并启用logminer: SQL> shutdown immediate 数据库已经关闭. ...