当前位置:网站首页>数组 两数之和
数组 两数之和
2022-06-10 20:50:00 【Morris_】
数组 LC 两数之和
给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。
你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。
你可以按任意顺序返回答案。
- Swift 实现
输入 [0, 0, 1, 0]
var nums: [Int] = [0, 0, 1, 0]
print(twoSum(nums, 1))
func twoSum(_ nums: [Int],_ target: Int) -> [Int] {
for i in 0..<nums.count {
for j in (i+1)..<nums.count {
if nums[i] + nums[j] == target {
return [i, j]
}
}
}
return []
}
输出 [0, 2]
边栏推荐
- 详解MATLAB中与矩阵运算有关的算术运算符(加、减、乘、除、点乘、点除、乘方)
- Tableau auto - fabriqué
- The system needs to scan all the files and try to identify the cover of the video
- Introduction to ZigBee module wireless transmission star topology networking structure
- SoC development environment and hardware development preparation
- [qingniaochangping campus of Peking University] the coordinated development of vocational education and general education, will this year's high school entrance examination be easy?
- Abbkine column exkine Pro animal cell / tissue Total Protein Extraction Kit
- Quick start to VISSIM simulation
- I'm doing something cool
- System reinstallation and system performance query
猜你喜欢

Practical | how to use burp suite for password blasting!

SQL第四练:字符串处理函数
Super detailed tutorial for installing mysql8 in centos7 (no pit!)
![[1024 ways to play windows azure] 75 Fast cloud database migration seamlessly migrate alicloud RDS SQL server to azure SQL databas](/img/00/798455f2db289e3aaed36981ea1e7c.png)
[1024 ways to play windows azure] 75 Fast cloud database migration seamlessly migrate alicloud RDS SQL server to azure SQL databas

Naturalspeech model synthetic speech achieves human speech level for the first time in CMOS test
CentOS7安装MySQL8的超级详细教程(无坑!)

Before we learn about high-performance computing, let's take a look at its history

SoC development environment and hardware development preparation

2022-06-09 RK817 PMU 電池溫度檢測
Detailed steps and actual records of SQL server2019 installation (available for hands-on test)
随机推荐
Mysql中创建4种索引的不同方式
Realize OSD reverse color on YUV image according to background color
Leetcode advanced path - reverse string
【北大青鸟昌平校区】职教与普教协调发展,今年的中考会容易吗?
Summary of common mysql8 commands in centos7 environment
Detailed steps and actual records of SQL server2019 installation (available for hands-on test)
初中毕业生,选择中职学校也可以升入高等学府
[qingniaochangping campus of Peking University] the coordinated development of vocational education and general education, will this year's high school entrance examination be easy?
SQL Server2019安装的详细步骤实战记录(亲测可用)
Signal and system review 1
Abbexa cdan1 siRNA instruction manual
Cordova Plugin /JPush PhoneGap 极光推送_本地推送_消息推送
旋转导航栏
Abbexa 8-OHdG CLIA kit solution
C language -- 4 first-time constant
软件测试工程师是做什么的?
01js basic null and undefined difference type conversion = = code block logical operator
H265 Nalu type judgment and SPS data analysis
Leetcode advanced path - Search insertion location
[nk] 牛客月賽51 G計算題