【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 ...
随机推荐
- 数的长度---nyoj69
超时 #include <stdio.h>#include <string.h>#define M 1000001int shu[M]; int main(){ int n, ...
- Java代理模式
java代理模式及动态代理类 1. 代理模式 代理模式的作用是:为其他对象提供一种代理以控制对这个对象的访问.在某些情况下,一个客户不想或者不能直接引用另一个对象,而代理对象可以在客户端和目 ...
- Asp.net点击按钮弹出文件夹选择框的实现(网页)
本文地址:http://www.cnblogs.com/PiaoMiaoGongZi/p/4092112.html 在Asp.net网站实际的开发中,比如:需要实现点击一个类似于FileUpload的 ...
- DevExpress GridView对表格的部分说明
1. int[] selects = this.m_grdView1.GetSelectedRows(); // 获取选中的行,可能是几行 2. this.m_grdView1.GetRowCellV ...
- log4j.properties 配置的学习整理
参考资料: log4j.properties:用来做什么的(日志) Log4j:由2部分组成 :loggers(记录器) ----日志的类别 appender(输出源) ...
- C#使用ajaxForm进行上传图片
<div class='imgOuter addImgBtn l_canshu' id='ImagePath1' value=''> <img src="../Images ...
- 使用apache.lang包安全简洁地操作Java时间
引言 最近偶遇apache开发的工作java工具包,一使用,就发现自己爱上它了.不多说了,下面介绍org.apache.commons.lang3.time包中处理java程序员为之头疼的时间的类. ...
- tableView主从表在storyboard连线是 Selcetion Segue和Accessory Action的区别
当按住Ctorl这样连线时会出现,当选择Selection Segue下面的push时,点击cell的任何位置都会跳转到下一个tableView,当选择Accessory Action的下面的push ...
- C# base64编码的文本与图片互转
/// <summary> /// base64编码的文本转为图片 /// </summary> /// <param name="txtFilePath&qu ...
- PHP5与MySQL数据库操作
1 建立数据库表: 2 读取数据 2.1 建立01.php 2.2 建立member.php 3 修改数据 3.1 建立level.php(修改数据) 3.2 建立up_level.php 4 ...