当前位置:网站首页>[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]边栏推荐
- The girlfriend said: if you want to understand the three MySQL logs, I will let you heiheihei!
- Usage of C set
- 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
- 酒旅板块复苏,亚朵继续上市梦,距离“新住宿经济第一股“还有多远?
- Basic knowledge of Embedded Network - introduction of mqtt
- 20220215-ctf-misc-buuctf-ningen--binwalk analysis --dd command separation --archpr brute force cracking
- Some views on libco
- The question of IBL precomputation is finally solved
- Stack frame
- How to scroll uitableview to a specific position - how to scroll uitableview to specific position
猜你喜欢

Sword finger offer 18 Delete the node of the linked list

A letter to 5000 fans!

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

Deployment of mini version message queue based on redis6.0

What should I do without 50W bride price

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

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

剑指 Offer 18. 删除链表的节点

Confirm() method of window

SAP ui5 beginner tutorial 19 - SAP ui5 data types and complex data binding
随机推荐
【原创】 PLSQL 索引排序优化
Wechat official account development (1) introduction to wechat official account
Sword finger offer 18 Delete the node of the linked list
A single element in an ordered array
2022 is half way through. It's hard to make money
IBL预计算的疑问终于解开了
CMU15445 (Fall 2019) 之 Project#1 - Buffer Pool 详解
Ranger plug-in development (Part 2)
Cmu15445 (fall 2019) project 1 - buffer pool details
最长的可整合子数组的长度
$watch will not trigger data change - $watch not firing on data change
P4 learning - Basic tunneling
什么是产品思维
解决 error MSB8031: Building an MFC project for a non-Unicode character set is deprecated.
女朋友说:你要搞懂了MySQL三大日志,我就让你嘿嘿嘿!
剑指 Offer 18. 删除链表的节点
The longest selling mobile phone in China has been selling well since its launch, crushing iphone12
Left join displays the specified value when the left join matching data is null
问题解决:如何管理线程私有(thread_local)的指针变量
SAP ui5 beginner tutorial 19 - SAP ui5 data types and complex data binding