1. Two Sum

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

Example:

Given nums = [, , , ], target = ,

Because nums[] + nums[] =  +  = ,
return [, ].

ANSWER:

 class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
for i, v1 in enumerate(nums):
for j, v2 in enumerate(nums[i + :]):
if (v1 + v2) == target:
return [i,j+i+]

ANSWER

(python)leetcode刷题笔记 01 TWO SUM的更多相关文章

  1. 【leetcode刷题笔记】Combination Sum II

    Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...

  2. 【leetcode刷题笔记】Path Sum

    Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...

  3. (python)leetcode刷题笔记03 Longest Substring Without Repeating Characters

    3. Longest Substring Without Repeating Characters Given a string, find the length of the longest sub ...

  4. (python)leetcode刷题笔记05 Longest Palindromic Substring

    5. Longest Palindromic Substring Given a string s, find the longest palindromic substring in s. You ...

  5. (python)leetcode刷题笔记04 Median of Two Sorted Arrays

    4. Median of Two Sorted Arrays There are two sorted arrays nums1 and nums2 of size m and n respectiv ...

  6. 【leetcode刷题笔记】Two Sum

    Given an array of integers, find two numbers such that they add up to a specific target number. The ...

  7. 【leetcode刷题笔记】Combination Sum

    Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...

  8. 18.9.10 LeetCode刷题笔记

    本人算法还是比较菜的,因此大部分在刷基础题,高手勿喷 选择Python进行刷题,因为坑少,所以不太想用CPP: 1.买股票的最佳时期2 给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. ...

  9. LeetCode刷题笔记和想法(C++)

    主要用于记录在LeetCode刷题的过程中学习到的一些思想和自己的想法,希望通过leetcode提升自己的编程素养 :p 高效leetcode刷题小诀窍(这只是目前对我自己而言的小方法,之后会根据自己 ...

随机推荐

  1. 极光IM简单接入步骤

    最近生接触了一下android,尝试导入极光的demo到android study 各种错误,然后下载极光生成的项目也是各种错误,感觉好像有点脱离时代了,记得以前用eclipse写android只需要 ...

  2. 为类型“xxxx”多次调用了 Map,且其中至少有一个调用未指定目标表名称。

    ef的继承映射真的是能搞死人啊...小结一下: 下图中的代码,ResponseTextMessage.ResponseNewsMessage.ResponseMethodMessage等几个类都是Re ...

  3. MVC身份验证Attribute简易版

    public class MemberValidationAttribute : AuthorizeAttribute { protected override bool AuthorizeCore( ...

  4. STM32F103片外运行代码分析

    STM32F103片外运行代码分析 STM32F103有三种启动方式: 1.从片内Flash启动: 2.从片内RAM启动: 3.从片内系统存储器启动,内嵌的自举程序,用于串口IAP. 无法直接在片外N ...

  5. win764 ping不能用的问题

    1.某日发现,ping突然用不了了 2.百度一搜,有如下解答: 1.右击计算机点属性之后找到系统属性下的环境变量: 2.找到系统变量的"path"之后按“编辑”: 3.变量值前面的 ...

  6. 来看看Uber的司机支持服务签到及预约系统的架构设计思路

    Uber的Greenlight Hubs(GLH)在全球拥有超过700个分支机构,为合作车主提供从账户和支付到车辆检查和车主注册等各方面的人工支持.为了给合作车主创造更好的体验并提高客户满意度,Ube ...

  7. ssm调用后台oracle存储过程统计分析数据

    笔者所在项目需要一个统计本机构近6月收入情况(分两种).本机构下级机构收入情况的需求,数据量为百万级. 具体需求是时间.机构都不确定,可为入参. 综合考虑后决定使用后台存储过程统计. 基础表结构如下: ...

  8. jQuery 遍历 - children() 方法 获取指定id下子元素的值

    <a id="Aobj_2_2" class="" specid="2" specvid="2" href=&qu ...

  9. (Linux学习笔记一:压缩)[20180209]

    学习笔记一:压缩 2015年2月5日 上午 10:23 压缩命令 压缩文件的扩展名大多是*.tar.*.tar.gz.*.tgz.*.gz.*.Z.*.bz2 常见的压缩命令gzip与bzip2,其中 ...

  10. 06JavaScript变量

    JavaScript 变量 变量是用于存储信息的"容器". var x=5; var y=6; var z=x+y; 就像代数那样 x=5 y=6 z=x+y 在代数中,我们使用字 ...