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. 第25章 串行FLASH文件系统FatFs

    25.1  文件系统 即使读者可能不了解文件系统,读者也一定对“文件”这个概念十分熟悉.数据在PC上是以文件的形式储存在磁盘中的,这些数据的形式一般为ASCII码或二进制形式.在上一章我们已经写好了Q ...

  2. Context initialization failed org.springframework.beans.factory.BeanCreationException

    严重: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error cre ...

  3. 737 MAX 8-Think

    波音 737 MAX 8的事故,凸显传感器数据在失真的情况下,软件系统需要如何设计的问题:这点感觉波音那么大的公司,不应该不会没有考虑到. 正常来说传感器给出错误的数据,通常是计算出错误的结果,就像做 ...

  4. OS--lab0+lab1+lab4+lab5+lab6+lab7

    URL:https://github.com/Chasssser/MytestOR(Linux) git clone https://github.com/Chasssser/Mytest

  5. Jquery之倒计时计算

      setInterval(); function setDate(setTime){ var date = new Date();//获取系统当前时间 )+)+"-"+date. ...

  6. css:url链接去下划线+点击前黑色+点击时灰色+点击后黑色

    一般的文章列表 加了样式之后的效果 附上css代码 /*点击前*/ a:link{ color: black; } /*点击后*/ a:visited{ color: black; } /*点击时*/ ...

  7. C#获取本地磁盘信息

    直接上干货简单易懂 //磁盘监控(远程/本地) //需要引用System.Management.dll public class RemoteMonitoring { private static s ...

  8. JavaScript - 异步的前世今生

    ​ 在开始接触JavaScript的时候,书上有一句话我记忆深刻,JavaScript是一门单线程语言,不管从什么途径去获取这个消息,前端开发者都会记住,哦~~,JavaScript是一门单线程语言, ...

  9. operator.attrgetter() 进行对象排序

    ## 使用operator.attrgetter() 进行对象排序 from operator import attrgetter class Student: def __init__(self, ...

  10. QQ空间|qq人气号怎么赚钱?

    回报,付出的终极诉求,咱不论情怀. 在<怎么做一个QQ人气号>中,笔者大致提及,打造人气空间的流程,这里简单剖析下QQ人气空间的盈利模式. 关键词:转让,出售,广告,微商,合作,网红,接推 ...