当前位置:网站首页>[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]边栏推荐
- 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
- From January 11, 2007 to January 11, 2022, I have been in SAP Chengdu Research Institute for 15 years
- 第53章 从业务逻辑实现角度整体性理解程序
- [original] PLSQL index sorting optimization
- Join table query select generation
- Oracle table creation and management
- Self examination before school starts
- CMU15445 (Fall 2019) 之 Project#1 - Buffer Pool 详解
- 给按钮的边框和文字设置不同的背景色
- 合适的工作就是好工作
猜你喜欢

2022-2028 global single travel industry research and trend analysis report

初识 Flutter 的绘图组件 — CustomPaint

Metauniverse and virtual reality (II)

PHP online confusion encryption tutorial sharing + basically no solution

Introduction to ES6 promise, new features of ES7 and es8 async and await

【原创】 PLSQL 索引排序优化

MySQL variables, stored procedures and functions

Sword finger offer 18 Delete the node of the linked list

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

Unit test concept and purpose
随机推荐
对libco的一点看法
Vnctf 2022 cm CM1 re reproduction
【日常记录】——对BigDecimal除法运算时遇到的Bug
Interface documentation system - Yapi
P4 learning - Basic tunneling
leetcode 474. Ones and zeroes (medium)
2022-2028 global PTFE lined valve industry research and trend analysis report
2022-2028 global weight loss ginger tea industry research and trend analysis report
The real topic of the 11th provincial competition of Bluebridge cup 2020 - crop hybridization
Basic data structure of redis
女朋友说:你要搞懂了MySQL三大日志,我就让你嘿嘿嘿!
Multi graph explanation of resource preemption in yarn capacity scheduling
Deployment of mini version message queue based on redis6.0
From January 11, 2007 to January 11, 2022, I have been in SAP Chengdu Research Institute for 15 years
[2023 MediaTek approved the test questions in advance] ~ questions and reference answers
Luogu p1168 median
2022-2028 global ultra high purity electrolytic iron sheet industry research and trend analysis report
2022-2028 global encrypted external hard disk industry research and trend analysis report
Oracle-表的创建与管理
Tcp/ip protocol stack, about TCP_ RST | TCP_ ACK correct attitude