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. OpenCV处理文件、视频和摄像头

    图像的本质(图像可以用数组来表示) import numpy as np import cv2 img = np.zeros((3, 3), dtype=np.uint8) print(img, im ...

  2. 六、while循环

    案例1: do while 循环  很少用到. for循环和while循环用的最多.

  3. 依据系统语言、设备、url 重定向对应页面

    1. 思路 获取浏览器语言.页面名称.区分手机端与电脑 根据特定方式命名 html 文件,然后独立文件,重定向 eg: - root -  gap.html     gap -    index.ht ...

  4. 利用sql报错帮助进行sql注入

    我们可以利用sql报错帮助进行sql注入,这里以sql server 为例: sql查询时,若用group by子句时,该子句中的字段必须跟select 条件中的字段(非聚合函数)完全匹配,如果是se ...

  5. Haproxy学习总结

    一.Haproxy介绍 1.实现了一种事件驱动,单一进程模型,支持数万计的并发连接,用于为tcp和http应用程序提供高可用,负载均衡和代理服务的解决方案,尤其适用于高负载且需要持久连接或7层处理机制 ...

  6. spring中spEL常用应用场景

    spEL表达式表示:#{} 一.基本类型值运算操作 {}可以放置数字,字符串,布尔型,表达式(运算,正则,逻辑).这个应用场景和EL表达式一样的,实际中用的也不多. 注意:在XML中表示==,> ...

  7. 转(HBuilder 打包流程)

    1.运行HBuilder---百度搜索HBuilder,官网下载安装包,解压,运行HBuilder.exe.注册账号,并登陆 2.新建app---在左边右键,选择新建APP,或者,点击中间的新建app ...

  8. token和sign

    前言 在app开放接口api的设计中,避免不了的就是安全性问题,因为大多数接口涉及到用户的个人信息以及一些敏感的数据,所以对这些接口需要进行身份的认证,那么这就需要用户提供一些信息,比如用户名密码等, ...

  9. CreateRemoteThread

    CreateRemoteThread是一个Windows API函数,它能够创建一个在其它进程地址空间中运行的线程(也称:创建远程线程)..

  10. DeepFaceLab更新至2019.12.19

    简而言之就是:人脸转换更加稳定和精确,切脸上下边界对齐,增加侧脸和嘴巴的识别面积,所以在这个版本之前的模型需要额外的训练.好消息是,如果你目前素材的嘴巴和侧脸识别有问题,可以重新提取脸部. 之前和之后 ...