当前位置:网站首页>[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]边栏推荐
- 20220215 misc buctf easycap Wireshark tracks TCP flow hidden key (use of WinHex tool)
- 连表查询 select 生成
- 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
- From January 11, 2007 to January 11, 2022, I have been in SAP Chengdu Research Institute for 15 years
- 2022-2028 global weight loss ginger tea industry research and trend analysis report
- P4学习——Basic Tunneling
- MySQL storage engine
- Stack frame
- 初识 Flutter 的绘图组件 — CustomPaint
- None of the following candidates is applicable because of a receiver type mismatch
猜你喜欢

From January 11, 2007 to January 11, 2022, I have been in SAP Chengdu Research Institute for 15 years

Oracle临时表详解

Vnctf 2022 cm CM1 re reproduction

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

PHP online confusion encryption tutorial sharing + basically no solution

20220215-ctf-misc-buuctf-ningen--binwalk analysis --dd command separation --archpr brute force cracking

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

Docsify building a personal minimalist knowledge warehouse

Set different background colors for the border and text of the button

What if the disk of datanode is full?
随机推荐
Chapter 53 overall understanding of procedures from the perspective of business logic implementation
IBL预计算的疑问终于解开了
The question of IBL precomputation is finally solved
left join左连接匹配数据为NULL时显示指定值
CSDN常用复杂公式模板记录
问题解决:如何管理线程私有(thread_local)的指针变量
2022-2028 global PTFE lined valve industry research and trend analysis report
Host FL Studio fruit music production daw20.9
Mindjet mindmanager2022 mind map decompression installer tutorial
Using asyncio for concurrency
深度学习的历史
MySQL storage engine
NE555 waveform generator handle tutorial NE555 internal structure (I)
What if the disk of datanode is full?
Problem solving: how to manage thread_local pointer variables
Join table query select generation
2022-2028 global electric yacht industry research and trend analysis report
NE555波形发生器手把手教程之NE555内部结构(一)
A proper job is a good job
Basic knowledge of Embedded Network - introduction of mqtt