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. sql server 符号函数sign

    --SIGN(x)返回参数的符号,x的值为负.零或正时,返回结果依次为-1.0或1 示例:select SIGN(-21), SIGN(0), SIGN(21) 结果:-1  0  1

  2. Servlet监听器——实现在线登录人数统计小例子

    一.概念 servlet监听器的主要目的是给web应用增加事件处理机制,以便更好的监视和控制web应用的状态变化,从而在后台调用相应处理程序. 二.监听器的类型 1.根据监听对象的类型和范围,分为3类 ...

  3. springcloud-概念

    springcloud-概念 一.架构演进过程 单体架构----分布式架构----SOA(eg.dubbo)服务治理架构----微服务 随着互联网的发展,需求的激增致使网站应用规模的扩大,最后转成了技 ...

  4. Git小结---So far.......

    基本的: 1. 在配置了SSH Key的情况下,clone项目时使用:git clone git@github.com/用户名/仓库名.git  使用这种方式而不使用https的方式的好处在于,在pu ...

  5. vue报错——Module not found: Error: Can't resolve 'less-loader sass' in ...

    npm install sass-loader -D npm install node-sass -D

  6. JS实现hasClass addClass removeClass

    // 判断class有无 function hasClass(ele, cls) { if (ele) { cls = cls || '' if (cls.replace(/\s/g, '').len ...

  7. java 求数组最大子序列之和

    经典问题: 给定一个int[]数组,求其最大子序列之和(条件:数组中不全部都是负数). 最优算法,线性时间复杂度: public static int maxSubSum(int[] a){ int ...

  8. laravel中间件失效,配置文件重新加载

    composer dump-autoload php artisan cache:clear 清理视图缓存 php atisan view:clear 清除运行缓存 php artisan cache ...

  9. centos7 php-fpm 开机启动

    拷贝php-fpm脚本至/etc/init.d目录(文件在php解压目录) cp /usr/local/src/php-/sapi/fpm/init.d.php-fpm /etc/init.d/php ...

  10. 一、模型验证CoreWebApi 管道方式(非过滤器处理)2(IApplicationBuilder扩展方法的另一种写法)

    一. 自定义中间件类的方式用一个单独类文件进行验证处理 Configure下添加配置 //app.AddAuthorize(); AddAuthorize因为参数(this IApplicationB ...