#-*- 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的更多相关文章

  1. 【leetcode❤python】 303. Range Sum Query - Immutable

    #-*- coding: UTF-8 -*- #Tags:dynamic programming,sumRange(i,j)=sum(j)-sum(i-1)class NumArray(object) ...

  2. 【leetcode❤python】 112. Path Sum

    #-*- coding: UTF-8 -*-# Definition for a binary tree node.# class TreeNode(object):#     def __init_ ...

  3. 【leetcode❤python】Sum Of Two Number

    #-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...

  4. 【leetcode❤python】 Sum of Left Leaves

    #-*- coding: UTF-8 -*- # Definition for a binary tree node.# class TreeNode(object):#     def __init ...

  5. 【leetcode❤python】 58. Length of Last Word

    #-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object):   ...

  6. 【leetcode❤python】 8. String to Integer (atoi)

    #-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1.以0开头的字符串,如01201215#2.以正负号开头的字符串,如'+121215':'-1215489' ...

  7. 【leetcode❤python】 396. Rotate Function

    #-*- coding: UTF-8 -*- #超时#        lenA=len(A)#        maxSum=[]#        count=0#        while count ...

  8. 【leetcode❤python】 299. Bulls and Cows

    #-*- coding: UTF-8 -*-class Solution(object):      def getHint(self, secret, guess):          " ...

  9. 【leetcode❤python】299. Bulls and Cows

    class Solution(object):    def getHint(self, secret, guess):        """        :type ...

随机推荐

  1. jQuery判断元素是否存在方法总结

    在jquery中判断元素是否存在我们可使用$("#div").length > 0)来判断了,意思就是判断元素长度了,如果没有肯定是不存在的哦,下面我来介绍介绍. 使用传统j ...

  2. Combination Lock

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a Micr ...

  3. 【iCore3 双核心板】例程三十三:SD_IAP_ARM实验——更新升级STM32

    实验指导书及代码包下载: http://pan.baidu.com/s/1jHmvQfk iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...

  4. Apache Spark源码走读之23 -- Spark MLLib中拟牛顿法L-BFGS的源码实现

    欢迎转载,转载请注明出处,徽沪一郎. 概要 本文就拟牛顿法L-BFGS的由来做一个简要的回顾,然后就其在spark mllib中的实现进行源码走读. 拟牛顿法 数学原理 代码实现 L-BFGS算法中使 ...

  5. mac下docker使用笔记

    安装docker https://docs.docker.com/mac/ 启动docker环境launchpad -> Docker Quickstart Terminal ##       ...

  6. JS弹出遮罩层

    // create div var mask=document.createElement("div"); mask.id="mask"; mask.style ...

  7. 转载:GridControl使用技巧

    一.如何解决单击记录整行选中的问题 View->OptionsBehavior->EditorShowMode 设置为:Click 二.如何新增一条记录 (1).gridView.AddN ...

  8. CocoaPods 学习

    参考文章 git address 1.简绍:CocoaPods是一个负责管理iOS项目中第三方开源代码的工具. 2.安装过程: $ sudo gem install cocoapods $ pod s ...

  9. 读源码之RESideMenu

    RESideMenu是github上比较出名的一个开源库,主要是实现侧滑菜单,现在有三千多个star了.效果如下.   据说创意来源于dribbble的一个设计,还是比较好看的.感兴趣的可以去gith ...

  10. 《30天自制操作系统》14_day_学习笔记

    harib11a--harib11c: 继续测试性能:我们在harib10h中进行了定时链表结构的改进“消除了移位处理”.下面我们设定490个定时器(它们都被设定启动50天才超时)来测试一下改进的效果 ...