博客
关于我
力扣刷题 两数之和
阅读量:30368 次
发布时间:2020-01-04 18:46:49

本文共 381 字,大约阅读时间需要 1 分钟。

力扣刷题

两数之和

力扣刷题## 记录
1.两数之和
给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。

你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。

在这里插入图片描述

class Solution:
# def twoSum(self, nums: List[int], target: int) -> List[int]:
def twoSum(self, nums, target):
for i in range(len(nums)):
if target-nums[i] in nums:
#增加了返回的两个数下表不能相同的判断
if i!=nums.index(target-nums[i]):
return i,nums.index(target-nums[i])

转载地址:http://evbhbu.baihongyu.com/

你可能感兴趣的文章
Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError:
查看>>
window环境下tomcat的控制台(Console)中文乱码
查看>>
判断地图中一个点是否在多边形内部
查看>>
eclipse中,spring的Spring的定时任务@Scheduled执行2次
查看>>
Ldap主从配置解决方案
查看>>
内网部署 JavaScript Arcgis API 服务
查看>>
Flex: 未绑定元素“esri:Map”的前缀“esri”
查看>>
Ambari更换mysql库
查看>>
JDK 1.8 启动 Eclipse 报Java was started but returned exit code=13...错误
查看>>
Flash Builder 4.7 破解
查看>>
ORACLE 模糊查询表名
查看>>
基于ssh互信的集群内主机密码批量修改
查看>>
hadoop的客户端安装失败
查看>>
Hive设置用户名和密码
查看>>
Hbase shell 的java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: Permission denied错误解决
查看>>
Linux设置JAVA的全局环境变量时的大坑
查看>>
Ldap目录结构
查看>>
Ambari修改UI界面的admin登陆密码
查看>>
两个NameNode未进入主备状态
查看>>
mysql:If 'mysql' is not a typo you can use command-not-found to lookup the package that contains
查看>>