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. Android平台上PMEM的使用及Platform设备注册(二)

    三.注册PMEM设备 这里我们除了描述PMEM设备,还将注册一个拥有memory空间和IRQ资源的示例设备example_device. 对于example_device,定义如下结构体: stati ...

  2. IBAction作用相当于void,NSLog(@"被调用的方法名是%s",__func__);

    IBAction作用相当于void,NSLog(@"被调用的方法名是%s",__func__);

  3. PCB测试点的设计要求

    测试点的设计要求:1.定位孔采用非金属化的定位孔 ,误差小于0.05mm.定位孔周围3mm不能有元件.2.测试点直径不小于0.8mm,测试点之间的间距不小于1.27mm,测试点离元件不小于1.27mm ...

  4. Jquery与js简单对比

    //Javascript window.onload=function () { var oBtn=document.getElementById('btn1'); oBtn.onclick=func ...

  5. Zabbix——部署(agent和proxy安装)

    前提条件: 已经完成对Zabbix-server的安装 已经完成对Mysql的安装 并且相互和正常使用和访问 配置agent服务器: rpm -Uvh https://repo.zabbix.com/ ...

  6. RPM包、YUM、system初始化进程基本知识

  7. 在IOS端点击数字后会调起系统拨号界面

    在IOS端点击数字后会调起系统拨号界面,解决方案: <meta name="format-detection" content="telephone=no" ...

  8. mongodb rebo 3T 执行出错 failed to execute script 但是执行成功 171条

    我现在也不清楚到底是什么原因 解决方法: 把你要执行的脚本保存到文件 在最上面添加下面两行代码:根据你的数据库 信息填写 conn = new Mongo('host:port'); db = con ...

  9. Spring异常重试框架Spring Retry

    Spring Retry支持集成到Spring或者Spring Boot项目中,而它支持AOP的切面注入写法,所以在引入时必须引入aspectjweaver.jar包. 快速集成的代码样例: @Con ...

  10. docker swarm的应用----docker集群的构建

    一.docker安装 这里我们安装docker-ce 的18.03版本 yum    -y remove docker  删除原有版本 #安装依赖包 [root@Docker ~]# yum -y i ...