当前位置:网站首页>[LeetCode] 两数之和【1】
[LeetCode] 两数之和【1】
2022-07-01 00:37:00 【山茶花开时。】
问题: 给定一个整数数组nums和一个整数目标值target,请你在该数组中找出和为目标值target的那两个整数,并返回它们的数组下标(注意: 数组中同一个元素在答案里不能重复出现)
示例1
输入: nums = [2,7,11,15], target = 9
输出: [0,1]
解释: 因为nums[0] + nums[1] == 9,返回[0, 1]
示例2
输入: nums = [3,2,4], target = 6
输出: [1,2]
示例3
输入: nums = [3,3], target = 6
输出: [0,1]
python3解题
def twoSum(nums, target):
for i in range(len(nums)):
for j in range(i+1,len(nums)):
if nums[i] + nums[j] == target:
return [i, j]
twoSum([2,7,11,15],9) # [0, 1]
twoSum([3,2,4],6) # [1, 2]
twoSum([3,3],6) # [0, 1]边栏推荐
- Error msb8031: building an MFC project for a non Unicode character set is deprecated
- Cmu15445 (fall 2019) project 1 - buffer pool details
- C#生成putty格式的ppk文件(支持passphrase)
- Packing and unpacking of C #
- CMU15445 (Fall 2019) 之 Project#1 - Buffer Pool 详解
- Oracle-表的创建与管理
- ArrayList分析1-循环、扩容、版本
- Teach you how to use Hal library to get started -- become a lighting master
- Implementation of date class
- P4学习——Basic Tunneling
猜你喜欢

What should I do without 50W bride price

SAP ui5 beginner tutorial 19 - SAP ui5 data types and complex data binding

20220215 CTF misc buuctf Xiaoming's safe binwalk analysis DD command separate rar file archpr brute force password cracking

C#生成putty格式的ppk文件(支持passphrase)
![[daily record] - bug encountered in BigDecimal division operation](/img/82/3105586841076b9bb1c57eac221ddf.png)
[daily record] - bug encountered in BigDecimal division operation

2022-2028 global encrypted external hard disk industry research and trend analysis report

Can JDBC based on openjdk connect to MySQL?

Sword finger offer 19 Regular Expression Matching

NE555 waveform generator handle tutorial NE555 internal structure (I)

Member management applet actual development 07 page Jump
随机推荐
2022-2028 global weight loss ginger tea industry research and trend analysis report
PyTorch安装并使用gpu加速
实验八 T-sql,存储过程
Oracle temporary table explanation
From January 11, 2007 to January 11, 2022, I have been in SAP Chengdu Research Institute for 15 years
剑指 Offer 19. 正则表达式匹配
Sword finger offer 18 Delete the node of the linked list
2022-2028 global encrypted external hard disk industry research and trend analysis report
Line number of Jenkins pipeline script execution exception
SAP ui5 beginner tutorial 19 - SAP ui5 data types and complex data binding
运动与健康
Confirm() method of window
Authentication principle of Ranger plug-in
Teach you how to use Hal library to get started -- become a lighting master
Gavin's insight on the transformer live broadcast course - rasa project's actual banking financial BOT Intelligent Business Dialogue robot system startup, language understanding, dialogue decision-mak
P4 learning - Basic tunneling
Multi graph explanation of resource preemption in yarn capacity scheduling
Wechat official account development (1) introduction to wechat official account
2022就要过去一半了,挣钱好难
Some views on libco