【leetcode❤python】 1. Two Sum
#-*- coding: UTF-8 -*- 
#AC源码【意外惊喜,还以为会超时】
class Solution(object):
    def twoSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
 
        for i in xrange(len(nums)):
            
            tmp=target-nums[i]
            curList=nums[i+1:]
     
            if curList.__contains__(tmp):
                return [i,i+curList.index(tmp)+1]
            else:continue
        return []
sol=Solution()
print sol.twoSum([-1,-2,-3,-4,-5],-8)
【leetcode❤python】 1. Two Sum的更多相关文章
- 【leetcode❤python】 303. Range Sum Query - Immutable
		#-*- coding: UTF-8 -*- #Tags:dynamic programming,sumRange(i,j)=sum(j)-sum(i-1)class NumArray(object) ... 
- 【leetcode❤python】 112. Path Sum
		#-*- coding: UTF-8 -*-# Definition for a binary tree node.# class TreeNode(object):# def __init_ ... 
- 【leetcode❤python】Sum Of Two Number
		#-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ... 
- 【leetcode❤python】 Sum of Left Leaves
		#-*- coding: UTF-8 -*- # Definition for a binary tree node.# class TreeNode(object):# def __init ... 
- 【leetcode❤python】 58. Length of Last Word
		#-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object): ... 
- 【leetcode❤python】 8. String to Integer (atoi)
		#-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1.以0开头的字符串,如01201215#2.以正负号开头的字符串,如'+121215':'-1215489' ... 
- 【leetcode❤python】 396. Rotate Function
		#-*- coding: UTF-8 -*- #超时# lenA=len(A)# maxSum=[]# count=0# while count ... 
- 【leetcode❤python】 299. Bulls and Cows
		#-*- coding: UTF-8 -*-class Solution(object): def getHint(self, secret, guess): " ... 
- 【leetcode❤python】299. Bulls and Cows
		class Solution(object): def getHint(self, secret, guess): """ :type ... 
随机推荐
- windows 精简/封装/部署
			给一个精简过的Windows7安装net35,提示自己到『打开或关闭Windows功能』里打开,然而发现并没有,只有一个ie9的功能.搜索尝试各种办法,显然都不行.用dism部署功能的工具,挂载一个完 ... 
- Customizing the Editor
			Use the General, Text Editor, Options Dialog Box to customize the appearance and functionality of th ... 
- WPF部署问题 解决:The application requires that the assembly...be installed in the GAC
			vs-->引用-->找到问题类库-->邮件属性--->特定版本-->false done 
- 贴片三极管-MOS管型号手册
			详细请查阅PDF: http://files.cnblogs.com/files/BinB-W/贴片三极管-MOS管型号手册.pdf 
- 《Android 性能测试初探》
			移动测试站点推荐: https://testerhome.com/ 专项相关帖子推荐: <Android 性能测试初探>合集 移动无线应用专项测试浅谈 公开课: [腾讯课堂]Testerh ... 
- centos7安装出现license information(license not accepted)解决办法
			若出现license information(license not accepted),即说明需要同意许可信息,输入1-回车-2-回车-c-回车-c回车,即可解决. 
- Eclipse安装maven插件报错
			Eclipse安装maven插件,报错信息如下: Cannot complete the install because one or more required items could not be ... 
- Hadoop学习笔记: MapReduce Java编程简介
			概述 本文主要基于Hadoop 1.0.0后推出的新Java API为例介绍MapReduce的Java编程模型.新旧API主要区别在于新API(org.apache.hadoop.mapreduce ... 
- Linux内核中大小端判定宏
			#include <stdio.h> ];unsigned long mylong;} endian_test = { {'l','?','?','b'} }; #define ENDIA ... 
- AjaxFileUpload 方法与原理分析
			AjaxFileUpload需求 传统的form表单方式上传文件, 必然会刷新整个页面. 那么在不刷新界面的情况下实现文件的上传呢? 在 HTML4下, 聪明的程序员们发明了 ajax file u ... 
