当前位置:网站首页>[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]边栏推荐
- 20220216 misc buuctf another world WinHex, ASCII conversion flag zip file extraction and repair if you give me three days of brightness zip to rar, Morse code waveform conversion mysterious tornado br
- Vnctf 2022 cm CM1 re reproduction
- 优质的水泵 SolidWorks模型素材推荐,不容错过
- 最长的可整合子数组的长度
- HDU 2488 A Knight's Journey(DFS)
- 运动与健康
- Stack frame
- Double linked list: initialize insert delete traversal
- 20220215-ctf-misc-buuctf-einstein-binwalk analyze picture-dd command separate zip file -- look for password in picture attribute
- Usage of C set
猜你喜欢

Date类的实现

The longest selling mobile phone in China has been selling well since its launch, crushing iphone12

C # Generate PPK files in Putty format (passthrough support)

Mindjet mindmanager2022 mind map decompression installer tutorial

PHP online confusion encryption tutorial sharing + basically no solution

2022-2028 global weight loss ginger tea industry research and trend analysis report

2022-2028 global capsule shell industry research and trend analysis report

Koa koa-combine-routers 分路由管理

The principle of journal node

Multi graph explanation of resource preemption in yarn capacity scheduling
随机推荐
初识 Flutter 的绘图组件 — CustomPaint
P4学习——Basic Tunneling
Oracle临时表详解
PyTorch安装并使用gpu加速
Exercises on recursion in C language
High quality pump SolidWorks model material recommended, not to be missed
Yboj mesh sequence [Lagrange interpolation]
什么是产品思维
Sword finger offer 18 Delete the node of the linked list
Golang treasure house recommendation
2022-2028 global public address fire alarm system industry research and trend analysis report
Analysis of blocktoken principle
Koa koa-combine-routers 分路由管理
20220215 CTF misc buuctf Xiaoming's safe binwalk analysis DD command separate rar file archpr brute force password cracking
What is product thinking
Oracle table creation and management
left join左连接匹配数据为NULL时显示指定值
2022-2028 global single travel industry research and trend analysis report
2022-2028 global weight loss ginger tea industry research and trend analysis report
Teach you how to use Hal library to get started -- become a lighting master