当前位置:网站首页>数组 是否存在重复元素
数组 是否存在重复元素
2022-06-10 20:50:00 【Morris_】
数组中是否存在重复元素
Swift
let array: [Int] = [1,1,1,3,3,4,3,2,4,2]
for i in 0..<array.count {
for j in (i+1)..<array.count {
if (array[i] == array[j]) {
print(true)
return
}
}
}
print(false)
函数实现如下
func containsDuplicate(_ nums: [Int]) -> Bool {
for i in 0..<nums.count {
for j in (i+1)..<nums.count {
if (nums[i] == nums[j]) {
return true
}
}
}
return false
}
调试
let array: [Int] = [1,1,1,3,3,4,3,2,4,2]
let duplicate: Bool = containsDuplicate(array)
print(duplicate)
边栏推荐
- 【MySQL】表数据的增删查改(DML)
- 自媒体视频创作如何选择领域?
- MySQL inserts query results into other tables
- SQL第四练:字符串处理函数
- Super detailed tutorial for installing mysql8 in centos7 (no pit!)
- Which city should I go to after I graduate from it? Which position has a high salary? Which companies have good treatment?
- CentOS7安装MySQL8的超级详细教程(无坑!)
- String analysis and use
- The process of keyword search in Oracle tables
- 学IT毕业后该去哪个城市?哪个岗位薪资高?哪些公司待遇好?
猜你喜欢

Calculus review 1

What do software test engineers do?

ThinkPHP v6.0.x反序列化漏洞复现
Detailed steps and actual records of SQL server2019 installation (available for hands-on test)

C language -- 7 operators

2022 - 06 - 09 rk817 PMU Battery Temperature Detection

Introduction to ZigBee module wireless transmission star topology networking structure
PHP pseudo protocol implementation command execution details

Which city should I go to after I graduate from it? Which position has a high salary? Which companies have good treatment?

Junior high school graduates who choose secondary vocational schools can also be promoted to institutions of higher learning
随机推荐
[Warning] TIMESTAMP with implicit DEFAULT value is deprecated
Abbexa acrylamide peg NHS instructions
Detailed steps and actual records of SQL server2019 installation (available for hands-on test)
String analysis and use
C language ---2 initial knowledge of data types
[nk] 牛客月賽51 G計算題
Leetcode advanced road - 125 Validate palindrome string
Naturalspeech model synthetic speech achieves human speech level for the first time in CMOS test
C language ---6 first knowledge of selection statement, loop statement, function and array
C language -- 7 operators
C language -- 3 variables for beginners
Calculus review 1
在模仿学习中进步的智能机器人
Introduction to database system -- Chapter 1 -- Introduction (important knowledge points)
2022-06-09 RK817 PMU 电池温度检测
【北大青鸟昌平校区】职教与普教协调发展,今年的中考会容易吗?
H265 Nalu type judgment and SPS data analysis
A WPF developed Print dialog box -printdialogx
初中毕业生,选择中职学校也可以升入高等学府
19 MySQL optimizations commonly used in projects