#-*- 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. windows 精简/封装/部署

    给一个精简过的Windows7安装net35,提示自己到『打开或关闭Windows功能』里打开,然而发现并没有,只有一个ie9的功能.搜索尝试各种办法,显然都不行.用dism部署功能的工具,挂载一个完 ...

  2. Customizing the Editor

    Use the General, Text Editor, Options Dialog Box to customize the appearance and functionality of th ...

  3. WPF部署问题 解决:The application requires that the assembly...be installed in the GAC

    vs-->引用-->找到问题类库-->邮件属性--->特定版本-->false done

  4. 贴片三极管-MOS管型号手册

    详细请查阅PDF: http://files.cnblogs.com/files/BinB-W/贴片三极管-MOS管型号手册.pdf

  5. 《Android 性能测试初探》

    移动测试站点推荐: https://testerhome.com/ 专项相关帖子推荐: <Android 性能测试初探>合集 移动无线应用专项测试浅谈 公开课: [腾讯课堂]Testerh ...

  6. centos7安装出现license information(license not accepted)解决办法

    若出现license information(license not accepted),即说明需要同意许可信息,输入1-回车-2-回车-c-回车-c回车,即可解决.

  7. Eclipse安装maven插件报错

    Eclipse安装maven插件,报错信息如下: Cannot complete the install because one or more required items could not be ...

  8. Hadoop学习笔记: MapReduce Java编程简介

    概述 本文主要基于Hadoop 1.0.0后推出的新Java API为例介绍MapReduce的Java编程模型.新旧API主要区别在于新API(org.apache.hadoop.mapreduce ...

  9. Linux内核中大小端判定宏

    #include <stdio.h> ];unsigned long mylong;} endian_test = { {'l','?','?','b'} }; #define ENDIA ...

  10. AjaxFileUpload 方法与原理分析

    AjaxFileUpload需求 传统的form表单方式上传文件,  必然会刷新整个页面. 那么在不刷新界面的情况下实现文件的上传呢? 在 HTML4下, 聪明的程序员们发明了 ajax file u ...