mycode  33.91%

class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
for i in range(len(nums)):
temp = target - nums[i]
if temp in nums[i+1:]:
return [i,nums[i+1:].index(temp)+i+1]

参考:

def two_sum(myList,target):
d = {}
for i,num in enumerate(myList):
print('...',i,target-num)
if target - num in d:
print('true')
print('...',i,target-num,d[target-num])
return [d[target-num],i]
d[num] = i
print(d)
myList = [2,7,11,15,6]
print(two_sum(myList,22))

leetcode-easy-array-1 two sum的更多相关文章

  1. [LeetCode] Split Array with Equal Sum 分割数组成和相同的子数组

    Given an array with n integers, you need to find if there are triplets (i, j, k) which satisfies fol ...

  2. Leetcode: Split Array Largest Sum

    Given an array which consists of non-negative integers and an integer m, you can split the array int ...

  3. [LeetCode] Split Array With Same Average 分割数组成相同平均值的小数组

    In a given integer array A, we must move every element of A to either list B or list C. (B and C ini ...

  4. [LeetCode] 325. Maximum Size Subarray Sum Equals k 和等于k的最长子数组

    Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If t ...

  5. 求和问题总结(leetcode 2Sum, 3Sum, 4Sum, K Sum)

    转自  http://tech-wonderland.net/blog/summary-of-ksum-problems.html 前言: 做过leetcode的人都知道, 里面有2sum, 3sum ...

  6. C++ STL@ list 应用 (leetcode: Rotate Array)

    STL中的list就是一双向链表,可高效地进行插入删除元素. List 是 C++标准程式库 中的一个 类 ,可以简单视之为双向 连结串行 ,以线性列的方式管理物件集合.list 的特色是在集合的任何 ...

  7. [leetcode]364. Nested List Weight Sum II嵌套列表加权和II

    Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...

  8. Leetcode 931. Minimum falling path sum 最小下降路径和(动态规划)

    Leetcode 931. Minimum falling path sum 最小下降路径和(动态规划) 题目描述 已知一个正方形二维数组A,我们想找到一条最小下降路径的和 所谓下降路径是指,从一行到 ...

  9. LeetCode(113) Path Sum II

    题目 Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given ...

  10. A. Array with Odd Sum Round #617(水题)

    A. Array with Odd Sum time limit per test 1 second memory limit per test 256 megabytes input standar ...

随机推荐

  1. JavaEE--JSP指令

    JSP指令用于提供整个JSP页面的相关信息以及用于JSP页面与容器之间的通信.JSP指令有三种:page指令.include指令.taglib指令 1.page指令 用于设定整个JSP页面的属性和相关 ...

  2. Elasticsearch入门教程(一):Elasticsearch及插件安装

    原文:Elasticsearch入门教程(一):Elasticsearch及插件安装 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:h ...

  3. [转载]如何通过ssh进行上传/下载

    [转载]如何通过ssh进行上传/下载 学校给配了服务器的用户账号,但是怎么向服务器中上传以及下载文件呢?Windows下可以使用Xftp和Xshell,但是Linux下能不能用命令行解决呢? 什么是S ...

  4. AQS之Condition

    一.引言 一般我们在使用锁的Condition时,我们一般都是这么使用,以ReentrantLock为例, ReentrantLock lock = new ReentrantLock(); Cond ...

  5. YOLOv3训练过程笔记

    本人使用的是linux平台,按照YOLO网页0https://pjreddie.com/darknet/yolo/的步骤操作进行下载darkenet程序包以及编译,之后可尝试用VOC2007的数据集测 ...

  6. composer 被墙后镜像设置

    这一步主要更改镜像,不从外网直接取,现在改成了中国的一家镜像站.就是下面这个地址. https://packagist.phpcomposer.com#阿里云的composer镜像源composer ...

  7. 使用parted 创建一个大于2T的分区

    1.查看现有分区 parted -l fdisk   -l     2.对/dev/sdb分一个区 [root@test ~]# parted /dev/sdb   (parted) mkpart  ...

  8. git 命令解析

    git 补丁 Git 提供了两种补丁方案:   (1)用 git diff 生成的UNIX标准补丁.diff文件:.diff文件只是记录文件改变的内容,不带有commit记录信息,多个commit可以 ...

  9. ui自动化之selenium操作(一)环境搭建

    1. python安装: 前面步骤可以看到,这里就不赘述了(我们在这里安装的是python3) 2. selenium安装: 前面我们都已经安装好pip了,所以这里咱们直接进入到python安装路径的 ...

  10. 详解WebService开发中四个常见问题(1)

    详解WebService开发中四个常见问题(1)   WebService开发中经常会碰到诸如WebService与方法重载.循环引用.数据被穿该等等问题.本文会给大家一些很好的解决方法. AD:WO ...